File tree Expand file tree Collapse file tree 15 files changed +48
-55
lines changed
s0230_kth_smallest_element_in_a_bst
s0234_palindrome_linked_list
s0236_lowest_common_ancestor_of_a_binary_tree
s0238_product_of_array_except_self
s0239_sliding_window_maximum
s0240_search_a_2d_matrix_ii
s0287_find_the_duplicate_number
s0295_find_median_from_data_stream
s0300_longest_increasing_subsequence Expand file tree Collapse file tree 15 files changed +48
-55
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 11package g0201_0300 .s0221_maximal_square ;
22
33// #Medium #Array #Dynamic_Programming #Matrix #Dynamic_Programming_I_Day_16
4- // #Big_O_Time_O(m*n)_Space_O(m*n) #2022_07_04_Time_7_ms_(72.35%)_Space_59.5_MB_(10 .55%)
4+ // #Big_O_Time_O(m*n)_Space_O(m*n) #2024_11_16_Time_6_ms_(97.07%)_Space_60.3_MB_(39 .55%)
55
66public class Solution {
77 public int maximalSquare (char [][] matrix ) {
Original file line number Diff line number Diff line change 22
33// #Easy #Top_100_Liked_Questions #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
44// #Data_Structure_I_Day_12_Tree #Level_2_Day_6_Tree #Udemy_Tree_Stack_Queue
5- // #Big_O_Time_O(n)_Space_O(n) #2022_07_04_Time_0_ms_ (100.00%)_Space_42_MB_(20.73 %)
5+ // #Big_O_Time_O(n)_Space_O(n) #2024_11_16_Time_0_ms_ (100.00%)_Space_40.6_MB_(95.51 %)
66
77import com_github_leetcode .TreeNode ;
88
Original file line number Diff line number Diff line change 22
33// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Binary_Search_Tree
44// #Data_Structure_II_Day_17_Tree #Level_2_Day_9_Binary_Search_Tree #Big_O_Time_O(n)_Space_O(n)
5- // #2022_07_04_Time_1_ms_(78.91%)_Space_45 .3_MB_(58.87 %)
5+ // #2024_11_16_Time_0_ms_(100.00%)_Space_44 .3_MB_(63.70 %)
66
77import com_github_leetcode .TreeNode ;
88
Original file line number Diff line number Diff line change 22
33// #Easy #Top_100_Liked_Questions #Two_Pointers #Stack #Linked_List #Recursion
44// #Level_2_Day_3_Linked_List #Udemy_Linked_List #Big_O_Time_O(n)_Space_O(1)
5- // #2022_07_04_Time_6_ms_(76.07%)_Space_97.6_MB_(56.14 %)
5+ // #2024_11_16_Time_4_ms_(84.46%)_Space_69_MB_(17.17 %)
66
77import com_github_leetcode .ListNode ;
88
Original file line number Diff line number Diff line change 22
33// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree
44// #Data_Structure_II_Day_18_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n)
5- // #2022_07_04_Time_10_ms_(56.51%)_Space_47.4_MB_(45.84 %)
5+ // #2024_11_16_Time_6_ms_(100.00%)_Space_44_MB_(98.99 %)
66
77import com_github_leetcode .TreeNode ;
88
Original file line number Diff line number Diff line change 11package g0201_0300 .s0238_product_of_array_except_self ;
22
33// #Medium #Top_100_Liked_Questions #Array #Prefix_Sum #Data_Structure_II_Day_5_Array #Udemy_Arrays
4- // #Big_O_Time_O(n^2)_Space_O(n) #2022_07_04_Time_1_ms_(100.00%)_Space_50.8_MB_(85.60 %)
4+ // #Big_O_Time_O(n^2)_Space_O(n) #2024_11_16_Time_1_ms_(99.66%)_Space_55.1_MB_(79.02 %)
55
66public class Solution {
77 public int [] productExceptSelf (int [] nums ) {
8- int product = 1 ;
9- int [] ans = new int [nums .length ];
10- for (int num : nums ) {
11- product = product * num ;
12- }
8+ int [] res = new int [nums .length ];
9+ int prefixProduct = 1 ;
1310 for (int i = 0 ; i < nums .length ; i ++) {
14- if (nums [i ] != 0 ) {
15- ans [i ] = product / nums [i ];
16- } else {
17- int p = 1 ;
18- for (int j = 0 ; j < nums .length ; j ++) {
19- if (j != i ) {
20- p = p * nums [j ];
21- }
22- }
23- ans [i ] = p ;
24- }
11+ res [i ] = prefixProduct ;
12+ prefixProduct *= nums [i ];
13+ }
14+ int suffixProduct = 1 ;
15+ for (int i = nums .length - 1 ; i >= 0 ; i --) {
16+ res [i ] *= suffixProduct ;
17+ suffixProduct *= nums [i ];
2518 }
26- return ans ;
19+ return res ;
2720 }
2821}
Original file line number Diff line number Diff line change 22
33// #Hard #Top_100_Liked_Questions #Array #Heap_Priority_Queue #Sliding_Window #Queue
44// #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k)
5- // #2022_07_04_Time_58_ms_(52.28%)_Space_145_MB_(50.60 %)
5+ // #2024_11_16_Time_26_ms_(95.89%)_Space_59.6_MB_(38.70 %)
66
77import java .util .LinkedList ;
88
Original file line number Diff line number Diff line change 22
33// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Matrix #Divide_and_Conquer
44// #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 #Big_O_Time_O(n+m)_Space_O(1)
5- // #2022_07_04_Time_7_ms_(86.73%)_Space_58.4_MB_(9.95 %)
5+ // #2024_11_16_Time_5_ms_(99.92%)_Space_45.8_MB_(60.21 %)
66
77public class Solution {
88 public boolean searchMatrix (int [][] matrix , int target ) {
Original file line number Diff line number Diff line change 22
33// #Easy #Top_100_Liked_Questions #Array #Two_Pointers #Algorithm_I_Day_3_Two_Pointers
44// #Programming_Skills_I_Day_6_Array #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1)
5- // #2022_07_06_Time_2_ms_(79.54%)_Space_55.7_MB_(5.98 %)
5+ // #2024_11_16_Time_2_ms_(83.99%)_Space_45.9_MB_(50.99 %)
66
77public class Solution {
88 public void moveZeroes (int [] nums ) {
You can’t perform that action at this time.
0 commit comments