File tree 11 files changed +48
-61
lines changed
s0114_flatten_binary_tree_to_linked_list
s0121_best_time_to_buy_and_sell_stock
s0124_binary_tree_maximum_path_sum
s0128_longest_consecutive_sequence
s0131_palindrome_partitioning
s0138_copy_list_with_random_pointer
s0142_linked_list_cycle_ii
11 files changed +48
-61
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package s0114_flatten_binary_tree_to_linked_list
2
2
3
3
// #Medium #Top_100_Liked_Questions #Depth_First_Search #Tree #Binary_Tree #Stack #Linked_List
4
4
// #Udemy_Linked_List #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(N)_Space_O(N)
5
- // #2024_03_19_Time_0_ms_ (100.00%)_Space_3.1_MB_(5.75 %)
5
+ // #2025_05_07_Time_0_ms_ (100.00%)_Space_4.88_MB_(66.49 %)
6
6
7
7
type TreeNode struct {
8
8
Val int
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ package s0121_best_time_to_buy_and_sell_stock
3
3
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
4
4
// #Data_Structure_I_Day_3_Array #Dynamic_Programming_I_Day_7 #Level_1_Day_5_Greedy #Udemy_Arrays
5
5
// #Top_Interview_150_Array/String #Big_O_Time_O(N)_Space_O(1)
6
- // #2024_03_19_Time_76_ms_(99.34%)_Space_7.4_MB_(98.91 %)
6
+ // #2025_05_07_Time_0_ms_(100.00%)_Space_9.74_MB_(72.19 %)
7
7
8
8
func maxProfit (prices []int ) int {
9
9
maxProfit := 0
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package s0124_binary_tree_maximum_path_sum
2
2
3
3
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Depth_First_Search
4
4
// #Tree #Binary_Tree #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General
5
- // #Big_O_Time_O(N)_Space_O(N) #2024_03_19_Time_10_ms_(89.68%)_Space_7.8_MB_(94.84 %)
5
+ // #Big_O_Time_O(N)_Space_O(N) #2025_05_07_Time_0_ms_(100.00%)_Space_10.08_MB_(59.76 %)
6
6
7
7
type TreeNode struct {
8
8
Val int
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package s0128_longest_consecutive_sequence
2
2
3
3
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Union_Find
4
4
// #Top_Interview_150_Hashmap #Big_O_Time_O(N_log_N)_Space_O(1)
5
- // #2024_03_19_Time_54_ms_ (99.84%)_Space_8.9_MB_(93 .24%)
5
+ // #2025_05_07_Time_4_ms_ (99.84%)_Space_10.05_MB_(99 .24%)
6
6
7
7
import "sort"
8
8
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package s0131_palindrome_partitioning
2
2
3
3
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Dynamic_Programming
4
4
// #Backtracking #Big_O_Time_O(N*2^N)_Space_O(2^N*N)
5
- // #2024_03_19_Time_221_ms_(97.16%)_Space_19.1_MB_(89.91 %)
5
+ // #2025_05_07_Time_18_ms_(92.42%)_Space_27.26_MB_(16.97 %)
6
6
7
7
func partition (s string ) [][]string {
8
8
var res [][]string
Original file line number Diff line number Diff line change 1
1
package s0136_single_number
2
2
3
3
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Bit_Manipulation
4
- // #Data_Structure_II_Day_1_Array #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Integers
5
- // #Top_Interview_150_Bit_Manipulation #Big_O_Time_O(N)_Space_O(1)
6
- // #2024_03_19_Time_8_ms_(95.49%)_Space_6.1_MB_(77.03 %)
4
+ // #LeetCode_75_Bit_Manipulation #Data_Structure_II_Day_1_Array
5
+ // #Algorithm_I_Day_14_Bit_Manipulation #Udemy_Integers #Top_Interview_150_Bit_Manipulation
6
+ // #Big_O_Time_O(N)_Space_O(1) #2025_05_07_Time_0_ms_(100.00%)_Space_7.82_MB_(83.54 %)
7
7
8
8
func singleNumber (nums []int ) int {
9
9
res := nums [0 ]
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package s0138_copy_list_with_random_pointer
2
2
3
3
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Linked_List
4
4
// #Programming_Skills_II_Day_14 #Udemy_Linked_List #Top_Interview_150_Linked_List
5
- // #Big_O_Time_O(N)_Space_O(N) #2024_03_19_Time_2_ms_(70.11%)_Space_3.6_MB_(96.36 %)
5
+ // #Big_O_Time_O(N)_Space_O(N) #2025_05_07_Time_0_ms_(100.00%)_Space_5.44_MB_(28.63 %)
6
6
7
7
type Node struct {
8
8
Val int
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ package s0139_word_break
3
3
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table
4
4
// #Dynamic_Programming #Trie #Memoization #Algorithm_II_Day_15_Dynamic_Programming
5
5
// #Dynamic_Programming_I_Day_9 #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
6
- // #Big_O_Time_O(M+max*N)_Space_O(M+N+max) #2024_03_20_Time_0_ms_ (100.00%)_Space_2.4_MB_(16.32 %)
6
+ // #Big_O_Time_O(M+max*N)_Space_O(M+N+max) #2025_05_07_Time_0_ms_ (100.00%)_Space_4.24_MB_(37.18 %)
7
7
8
8
func wordBreak (s string , wordDict []string ) bool {
9
9
if len (wordDict ) == 0 {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package s0141_linked_list_cycle
2
2
3
3
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Hash_Table #Two_Pointers #Linked_List
4
4
// #Data_Structure_I_Day_7_Linked_List #Udemy_Linked_List #Top_Interview_150_Linked_List
5
- // #Big_O_Time_O(N)_Space_O(1) #2024_03_20_Time_7_ms_(69.12%)_Space_4.6_MB_(82 .42%)
5
+ // #Big_O_Time_O(N)_Space_O(1) #2025_05_07_Time_4_ms_(76.55%)_Space_6.23_MB_(51 .42%)
6
6
7
7
type ListNode struct {
8
8
Val int
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package s0142_linked_list_cycle_ii
2
2
3
3
// #Medium #Top_100_Liked_Questions #Hash_Table #Two_Pointers #Linked_List
4
4
// #Data_Structure_II_Day_10_Linked_List #Level_1_Day_4_Linked_List #Udemy_Linked_List
5
- // #Big_O_Time_O(N)_Space_O(1) #2024_03_20_Time_5_ms_(69.02%)_Space_3.8_MB_(98.54 %)
5
+ // #Big_O_Time_O(N)_Space_O(1) #2025_05_07_Time_0_ms_(100.00%)_Space_6.80_MB_(18.18 %)
6
6
7
7
type ListNode struct {
8
8
Val int
@@ -17,26 +17,13 @@ type ListNode struct {
17
17
* }
18
18
*/
19
19
func detectCycle (head * ListNode ) * ListNode {
20
- if head == nil || head .Next == nil {
21
- return nil
22
- }
23
- slow := head
24
- fast := head
25
- for fast != nil && fast .Next != nil {
26
- fast = fast .Next .Next
27
- slow = slow .Next
28
- // intersected inside the loop.
29
- if slow == fast {
30
- break
20
+ m := map [* ListNode ]bool {}
21
+ for head != nil {
22
+ if m [head ] == true {
23
+ return head
31
24
}
25
+ m [head ] = true
26
+ head = head .Next
32
27
}
33
- if fast == nil || fast .Next == nil {
34
- return nil
35
- }
36
- slow = head
37
- for slow != fast {
38
- slow = slow .Next
39
- fast = fast .Next
40
- }
41
- return slow
28
+ return nil
42
29
}
You can’t perform that action at this time.
0 commit comments