链表逆序(JavaScript版)

 1 function reverseLinkedList(head) {
 2 
3
if (head === null || head.next === null) { 4 return head; 5 } 6 let newHead = null
7
while (head) { 8 let next = head.next 9 head.next = newHead 10 newHead = head 11 head = next 12 } 13 return newHead 14 }

 

posted @ 2020-02-14 09:32  flamestudio  阅读(632)  评论(0编辑  收藏  举报