Commit 77a8eeb
committed
Implement linked-list-cycle-ii
https://leetcode.com/problems/linked-list-cycle-ii
time: 4ms
time-rank: 98.90%
time-complexity: O(N)
space: 7.8MB
space-rank: 89.71%
space-complexity: O(1)
This solution adds no extra space but destroys the input.
While the cost of checking if a node is visited is still O(1), this solution
is faster than an unordered_set<LinkedList*> lookup because no hashing is
performed, values are likely still in cache, and it is simply a const
comparison.
Fixes #228
Signed-off-by: Christopher Friedt <[email protected]>1 parent f6c56f7 commit 77a8eeb
1 file changed
+5
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | 28 | | |
| 29 | + | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | | - | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 44 | | |
0 commit comments