1. How to reverse a linked list
Anonymous
function reverse(head) { if (!head.next) { return head } let prev = null let current = head let next = null while (current) { next = current.next current.next = prev prev = current current = next } return prev } function reverseRecursive(head, prev=null) { if (!head.next) { return head } let next = head.next let head.next = prev return reverseRecursive(prev, next) }
Check out your Company Bowl for anonymous work chats.