Skip to content

Commit 95abdbf

Browse files
committed
feat: add question 206
1 parent 6806ce5 commit 95abdbf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

206.反转链表.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @lc app=leetcode.cn id=206 lang=javascript
3+
*
4+
* [206] 反转链表
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* Definition for singly-linked list.
10+
* function ListNode(val) {
11+
* this.val = val;
12+
* this.next = null;
13+
* }
14+
*/
15+
/**
16+
* @param {ListNode} head
17+
* @return {ListNode}
18+
*/
19+
var reverseList = function(head) {
20+
if (!head) {
21+
return null;
22+
}
23+
24+
let result = head;
25+
head = head.next;
26+
result.next = null;
27+
while (head) {
28+
const next = head.next;
29+
head.next = result;
30+
result = head;
31+
head = next;
32+
}
33+
return result;
34+
};
35+
// @lc code=end

0 commit comments

Comments
 (0)