Skip to content

Commit

Permalink
Create 206-Reverse-Linked-List.js
Browse files Browse the repository at this point in the history
  • Loading branch information
veerbia authored Apr 3, 2022
1 parent a8e62c9 commit 9536df1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions javascript/206-Reverse-Linked-List.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var reverseList = function(head) {
let prev = null;

while (head) {
let next = head.next;
head.next = prev;
prev = head;
head = next;
}

return prev;
};

0 comments on commit 9536df1

Please sign in to comment.