Open quoniammm opened 9 years ago
/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode} head * @return {ListNode} */ var reverseList = function(head) { var prev = null, next; if(head === null) return null; while(true){ next = head.next; head.next = prev; prev = head; if(next !== null) head = next; else break; } return head; };