Skip to content

Commit 938f415

Browse files
committed
1. Reverse Linked List
1 parent d6e3890 commit 938f415

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

reverse-linked-list/sunjae95.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @description
3+
* brainstorming:
4+
* Thinking of stacking nodes like stacks while traveling
5+
*
6+
* time complexity: O(n)
7+
* space complexity: O(n)
8+
*/
9+
10+
var reverseList = function (head) {
11+
let answer = null;
12+
13+
const search = (target) => {
14+
if (target === null) return;
15+
16+
const node = new ListNode(target.val, answer);
17+
answer = node;
18+
19+
search(target.next);
20+
};
21+
22+
search(head);
23+
24+
return answer;
25+
};

0 commit comments

Comments
 (0)