File tree 4 files changed +49
-3
lines changed
4 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 226
226
| 209| [ Minimum Size Subarray Sum] ( https://leetcode.com/problems/minimum-size-subarray-sum/ ) | | Medium|
227
227
| 208| [ Implement Trie (Prefix Tree)] ( https://leetcode.com/problems/implement-trie-prefix-tree/ ) | | Medium|
228
228
| 207| [ Course Schedule] ( https://leetcode.com/problems/course-schedule/ ) | | Medium|
229
- | 206| [ Reverse Linked List] ( https://leetcode.com/problems/reverse-linked-list/ ) | [ java] ( ./algorithms/reverseLinkedList/Solution.java ) | Easy|
229
+ | 206| [ Reverse Linked List] ( https://leetcode.com/problems/reverse-linked-list/ ) | [ java] ( ./algorithms/reverseLinkedList/Solution.java ) , [ js ] ( ./algorithms/reverseLinkedList/reverseLinkedList.js ) | Easy|
230
230
| 205| [ Isomorphic Strings] ( https://leetcode.com/problems/isomorphic-strings/ ) | | Easy|
231
231
| 204| [ Count Primes] ( https://leetcode.com/problems/count-primes/ ) | | Easy|
232
232
| 203| [ Remove Linked List Elements] ( https://leetcode.com/problems/remove-linked-list-elements/ ) | [ js] ( ./algorithms/removeLinkedListElements/removeLinkedListElements.js ) ,[ java] ( ./algorithms/removeLinkedListElements/Solution.java ) | Easy|
284
284
| 145| [ Binary Tree Postorder Traversal] ( https://leetcode.com/problems/binary-tree-postorder-traversal/ ) | [ js] ( ./algorithms/binaryTreePostorderTraversal/binaryTreePostorderTraversal.js ) | Hard|
285
285
| 144| [ Binary Tree Preorder Traversal] ( https://leetcode.com/problems/binary-tree-preorder-traversal/ ) | [ js] ( ./algorithms/binaryTreePreorderTraversal/binaryTreePreorderTraversal.js ) | Medium|
286
286
| 143| [ Reorder List] ( https://leetcode.com/problems/reorder-list/ ) | | Medium|
287
- | 142| [ Linked List Cycle II] ( https://leetcode.com/problems/linked-list-cycle-ii/ ) | | Medium|
288
- | 141| [ Linked List Cycle] ( https://leetcode.com/problems/linked-list-cycle/ ) | | Medium|
287
+ | 142| [ Linked List Cycle II] ( https://leetcode.com/problems/linked-list-cycle-ii/ ) | [ js ] ( ./algorithms/linkedListCycleII/linkedListCycleII.js ) | Medium|
288
+ | 141| [ Linked List Cycle] ( https://leetcode.com/problems/linked-list-cycle/ ) | [ js ] ( ./algorithms/linkedListCycle/linkedListCycle.js ) | Medium|
289
289
| 140| [ Word Break II] ( https://leetcode.com/problems/word-break-ii/ ) | | Hard|
290
290
| 139| [ Word Break] ( https://leetcode.com/problems/word-break/ ) | | Medium|
291
291
| 138| [ Copy List with Random Pointer] ( https://leetcode.com/problems/copy-list-with-random-pointer/ ) | | Hard|
Original file line number Diff line number Diff line change
1
+ var hasCycle = function ( head ) {
2
+ if ( ! head || ! head . next ) return false ;
3
+ let slow = head , fast = head . next ;
4
+ while ( fast ) {
5
+ if ( slow . val === fast . val ) return true ;
6
+ if ( ! fast . next || ! fast . next . next ) return false ;
7
+ fast = fast . next . next ;
8
+ slow = slow . next ;
9
+ }
10
+ return false ;
11
+ } ;
Original file line number Diff line number Diff line change
1
+ var detectCycle = function ( head ) {
2
+ if ( head === null ) return null ;
3
+ let slow = head , fast = head ;
4
+ while ( fast !== null ) {
5
+ // 慢指针每次走 1步
6
+ slow = slow . next ;
7
+ if ( fast . next === null ) return null ;
8
+ // 快指针每次走2步
9
+ fast = fast . next . next ;
10
+ // 快慢指针相遇
11
+ if ( fast === slow ) {
12
+ // 这时把快指针重新指向头部节点
13
+ let ptr = head ;
14
+ // 当快慢指针相遇的时候,就是入环节点的位置
15
+ while ( ptr !== slow ) {
16
+ ptr = ptr . next ;
17
+ slow = slow . next ;
18
+ }
19
+ return ptr ;
20
+ }
21
+
22
+ }
23
+ return null ;
24
+ } ;
Original file line number Diff line number Diff line change
1
+ var reverseList = function ( head ) {
2
+ let prev = null ;
3
+ let curr = head ;
4
+ while ( curr ) {
5
+ let nextTemp = curr . next ;
6
+ curr . next = prev ;
7
+ prev = curr ;
8
+ curr = nextTemp ;
9
+ }
10
+ return prev ;
11
+ } ;
You can’t perform that action at this time.
0 commit comments