链表逆序(JavaScript版)

Posted flamestudio

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链表逆序(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 }

 

以上是关于链表逆序(JavaScript版)的主要内容,如果未能解决你的问题,请参考以下文章