Skip to content

Commit fc5e333

Browse files
committed
feat: 문제풀이 추가
1 parent f819319 commit fc5e333

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

reverse-linked-list/hwanmini.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// 시간복잡도: O(n)
2+
// 공간복잡도: O(1)
3+
4+
/**
5+
* Definition for singly-linked list.
6+
* function ListNode(val, next) {
7+
* this.val = (val===undefined ? 0 : val)
8+
* this.next = (next===undefined ? null : next)
9+
* }
10+
*/
11+
/**
12+
* @param {ListNode} head
13+
* @return {ListNode}
14+
*/
15+
var reverseList = function(head) {
16+
let curNode = head
17+
let preNode = null
18+
19+
while (curNode) {
20+
const nextNode = curNode.next
21+
curNode.next = preNode
22+
preNode = curNode
23+
curNode = nextNode
24+
}
25+
26+
27+
return preNode
28+
};

0 commit comments

Comments
 (0)