File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val, next) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.next = (next===undefined ? null : next)
6
+ * }
7
+ */
8
+ /**
9
+ * @param {ListNode } head
10
+ * @return {ListNode }
11
+ */
12
+ const reverseList = function ( head ) {
13
+ const rIter = ( head ) => {
14
+ let a = head ; let b = a ?. next
15
+ if ( a ) a . next = null
16
+ while ( b ) {
17
+ const c = b . next
18
+ b . next = a
19
+ a = b , b = c
20
+ }
21
+ return a
22
+ }
23
+ const rRecur = ( head ) => {
24
+ if ( ! head ?. next ) return head
25
+ const a = head . next
26
+ const newHead = rRecur ( a )
27
+ a . next = head
28
+ if ( head ) head . next = null
29
+ return newHead
30
+ }
31
+ // return rIter(head)
32
+ return rRecur ( head )
33
+ }
Original file line number Diff line number Diff line change @@ -58,3 +58,6 @@ Robot.prototype.getDir = function () {
58
58
* var param_2 = obj.getPos()
59
59
* var param_3 = obj.getDir()
60
60
*/
61
+ const r = new Robot ( 1 , 2 )
62
+
63
+ r . getDir ( )
Original file line number Diff line number Diff line change 25
25
- [ DFS] ( #dfs )
26
26
- [ 表达式求值] ( #表达式求值 )
27
27
- [ 状态机] ( #状态机 )
28
+ - [ 链表] ( #链表 )
28
29
- [ Links] ( #links )
29
30
30
31
## Problems
166
167
167
168
- 2055 . Plates Between Candles
168
169
170
+ ### 链表
171
+
172
+ - 206 . Reverse Linked List
173
+
169
174
## Links
170
175
171
176
- https://wisdompeak.github.io/lc-score-board/
You can’t perform that action at this time.
0 commit comments