File tree Expand file tree Collapse file tree 16 files changed +45
-53
lines changed
s0117_populating_next_right_pointers_in_each_node_ii
s0122_best_time_to_buy_and_sell_stock_ii
s0123_best_time_to_buy_and_sell_stock_iii
s0129_sum_root_to_leaf_numbers
s0149_max_points_on_a_line
s0150_evaluate_reverse_polish_notation
s0151_reverse_words_in_a_string Expand file tree Collapse file tree 16 files changed +45
-53
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 11package g0101_0200 .s0112_path_sum ;
22
33// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Data_Structure_I_Day_12_Tree
4- // #Top_Interview_150_Binary_Tree_General #2022_06_23_Time_0_ms_ (100.00%)_Space_43.8_MB_(36.11 %)
4+ // #Top_Interview_150_Binary_Tree_General #2025_03_06_Time_0_ms_ (100.00%)_Space_43.07_MB_(76.46 %)
55
66import com_github_leetcode .TreeNode ;
77
Original file line number Diff line number Diff line change 22
33// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Linked_List
44// #Algorithm_II_Day_7_Breadth_First_Search_Depth_First_Search
5- // #Top_Interview_150_Binary_Tree_General #2022_06_23_Time_0_ms_ (100.00%)_Space_44.7_MB_(65.49 %)
5+ // #Top_Interview_150_Binary_Tree_General #2025_03_06_Time_0_ms_ (100.00%)_Space_44.12_MB_(80.39 %)
66
77import com_github_leetcode .left_right .Node ;
88
Original file line number Diff line number Diff line change 22
33// #Medium #Array #Dynamic_Programming #Algorithm_I_Day_12_Dynamic_Programming
44// #Dynamic_Programming_I_Day_13 #Udemy_Dynamic_Programming #Top_Interview_150_Multidimensional_DP
5- // #2022_06_23_Time_2_ms_(94.63 %)_Space_44.2_MB_(36.02 %)
5+ // #2025_03_06_Time_1_ms_(99.79 %)_Space_44.45_MB_(35.64 %)
66
77import java .util .Arrays ;
88import java .util .List ;
Original file line number Diff line number Diff line change 22
33// #Medium #Top_Interview_Questions #Array #Dynamic_Programming #Greedy #Dynamic_Programming_I_Day_7
44// #Udemy_Arrays #Top_Interview_150_Array/String
5- // #2022_06_23_Time_1_ms_(96.82%)_Space_44.7_MB_(25.11 %)
5+ // #2025_03_06_Time_1_ms_(76.91%)_Space_45.72_MB_(69.34 %)
66
77public class Solution {
88 public int maxProfit (int [] prices ) {
Original file line number Diff line number Diff line change 11package g0101_0200 .s0123_best_time_to_buy_and_sell_stock_iii ;
22
33// #Hard #Array #Dynamic_Programming #Top_Interview_150_Multidimensional_DP
4- // #2022_06_23_Time_4_ms_(87.18%)_Space_78.4_MB_(61.70 %)
4+ // #2025_03_06_Time_4_ms_(74.67%)_Space_61.08_MB_(72.04 %)
55
66public class Solution {
77 public int maxProfit (int [] prices ) {
Original file line number Diff line number Diff line change 11package g0101_0200 .s0125_valid_palindrome ;
22
33// #Easy #Top_Interview_Questions #String #Two_Pointers #Udemy_Two_Pointers
4- // #Top_Interview_150_Two_Pointers #2022_06_23_Time_3_ms_(98.64 %)_Space_43.2_MB_(81.23 %)
4+ // #Top_Interview_150_Two_Pointers #2025_03_06_Time_2_ms_(99.11 %)_Space_43.15_MB_(70.82 %)
55
66public class Solution {
77 public boolean isPalindrome (String s ) {
Original file line number Diff line number Diff line change 22
33// #Hard #Top_Interview_Questions #String #Hash_Table #Breadth_First_Search
44// #Graph_Theory_I_Day_12_Breadth_First_Search #Top_Interview_150_Graph_BFS
5- // #2022_06_23_Time_37_ms_(94.58%)_Space_54.1_MB_(66.08 %)
5+ // #2025_03_06_Time_22_ms_(96.00%)_Space_45.97_MB_(83.68 %)
66
77import java .util .HashSet ;
88import java .util .List ;
Original file line number Diff line number Diff line change 11package g0101_0200 .s0129_sum_root_to_leaf_numbers ;
22
33// #Medium #Depth_First_Search #Tree #Binary_Tree #Top_Interview_150_Binary_Tree_General
4- // #2022_06_23_Time_0_ms_ (100.00%)_Space_41.8_MB_(46.81 %)
4+ // #2025_03_06_Time_0_ms_ (100.00%)_Space_41.47_MB_(30.87 %)
55
66import com_github_leetcode .TreeNode ;
77
Original file line number Diff line number Diff line change 11package g0101_0200 .s0134_gas_station ;
22
33// #Medium #Top_Interview_Questions #Array #Greedy #Top_Interview_150_Array/String
4- // #2022_06_24_Time_2_ms_(94.26%)_Space_62.5_MB_(87.11 %)
4+ // #2025_03_06_Time_2_ms_(97.52%)_Space_57.00_MB_(5.82 %)
55
66public class Solution {
77 public int canCompleteCircuit (int [] gas , int [] cost ) {
8- int sumGas = 0 ;
9- int sumCost = 0 ;
10- int curGas = 0 ;
11- int result = -1 ;
8+ int index = 0 ;
9+ int total = 0 ;
10+ int current = 0 ;
1211 for (int i = 0 ; i < gas .length ; i ++) {
13- curGas += gas [i ] - cost [i ];
14- // re-calculate the starting point
15- if (curGas < 0 ) {
16- result = -1 ;
17- curGas = 0 ;
18- } else if (result == -1 ) {
19- // set initial starting point
20- result = i ;
12+ int balance = gas [i ] - cost [i ];
13+ total += balance ;
14+ current += balance ;
15+ if (current < 0 ) {
16+ index = i + 1 ;
17+ current = 0 ;
2118 }
22- sumGas += gas [i ];
23- sumCost += cost [i ];
2419 }
25- if (sumGas < sumCost ) {
26- return -1 ;
27- }
28- return result ;
20+ return total >= 0 ? index : -1 ;
2921 }
3022}
You can’t perform that action at this time.
0 commit comments