Skip to content

Commit e72db68

Browse files
committed
feat: leetcode 2069:模拟, 206:反转链表
1 parent 23c23c2 commit e72db68

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

leetcode/残酷刷题/2069. Walking Robot Simulation II.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ Robot.prototype.getDir = function () {
5858
* var param_2 = obj.getPos()
5959
* var param_3 = obj.getDir()
6060
*/
61+
const r = new Robot(1, 2)
62+
63+
r.getDir()

leetcode/残酷刷题/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [DFS](#dfs)
2626
- [表达式求值](#表达式求值)
2727
- [状态机](#状态机)
28+
- [链表](#链表)
2829
- [Links](#links)
2930

3031
## Problems
@@ -166,6 +167,10 @@
166167

167168
- 2055. Plates Between Candles
168169

170+
### 链表
171+
172+
- 206. Reverse Linked List
173+
169174
## Links
170175

171176
- https://wisdompeak.github.io/lc-score-board/

0 commit comments

Comments
 (0)