Reverse a singly linked list.
click to show more hints.
Hint:
A linked list can be reversed either iteratively or recursively. Could you implement both?
贴个递归代码,一次Accept。
public ListNode reverseList(ListNode head) {
if (head == null || head.next == null)
return head;
ListNode temp = head.next;
ListNode reverseHead = reverseList(head.next);
temp.next = head;
head.
LeetCode-206:递归逆转链表解析

这篇博客介绍了如何解决LeetCode上的第206题——逆转链表,提供了递归解法的详细代码实现,并提到该问题还可以迭代解决。博主分享了自己之前对这一问题的研究,并提供了相关链接以供深入学习。
订阅专栏 解锁全文

2207

被折叠的 条评论
为什么被折叠?



