Skip to content

Commit cce4f9e

Browse files
authored
Merge pull request #948 from limlimjo/main
[jj7779607] Week7
2 parents d1af3d3 + aad4fd9 commit cce4f9e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

reverse-linked-list/limlimjo.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
var reverseList = function (head) {
13+
let [prev, curr] = [null, head];
14+
15+
while (curr) {
16+
[curr.next, prev, curr] = [prev, curr, curr.next];
17+
}
18+
19+
return prev;
20+
};
21+
22+
// 시간복잡도: O(n)
23+
// 공간복잡도: O(1)

0 commit comments

Comments
 (0)