Skip to content

Commit b5e01c3

Browse files
authored
Merge pull request #2545 from Cyjin-jani/main
[Cyjin-jani] WEEK 07 Solutions
2 parents f23034f + dbed84b commit b5e01c3

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

reverse-linked-list/Cyjin-jani.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {ListNode} head
3+
* @return {ListNode}
4+
*/
5+
const reverseList = function (head) {
6+
if (!head) return null;
7+
8+
let curr = head;
9+
let prev = null;
10+
11+
while (curr !== null) {
12+
const next = curr.next;
13+
curr.next = prev;
14+
prev = curr;
15+
curr = next;
16+
}
17+
18+
return prev;
19+
};

0 commit comments

Comments
 (0)