leetcode206-Reverse Linked List-反转链表

xiaoxiao2021-02-28  31

非递归:function reverseList(head) { var prev = null; while (head) { var next = head.next; head.next = prev; prev = head; head = next; } return prev; } 递归: function reverseList(head) { if (!head || !head.next) { return head; } var newHead = reverseList(head.next); head.next.next = head; head.next = null; return newHead; }
转载请注明原文地址: https://www.6miu.com/read-2400308.html

最新回复(0)