Reverse a LinkedList

 https://leetcode.com/problems/reverse-linked-list/submissions/971720915/

https://www.youtube.com/watch?v=S9kMVEUg-x4&ab_channel=Codevolution


var reverseList = function(head) {
    let prev=null;
    let current =head;
    while(current !==null){
        let next =current.next;
        current.next=prev;
        prev=current;
        current=next;
    }
    return prev
};

Comments

Popular posts from this blog

TO the new

4048