题目:

反转一个单链表。

示例:

输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
进阶:
你可以迭代或递归地反转链表。你能否用两种方法解决这道题?

分析:

递归,思路比较清晰

代码:

	public ListNode reverseList(ListNode head) {
		if (head == null || head.next == null)
			return head;
		ListNode tmp = reverseList(head.next);
		head.next.next = head;
        head.next = null;
		return tmp;
	}

效率:

leetcode:206. 反转链表

总结:

占用空间较高

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
猜你喜欢
  • 2021-12-29
  • 2021-07-05
  • 2021-09-02
  • 2022-01-14
  • 2021-12-26
  • 2021-05-15
  • 2021-09-20
相关资源
相似解决方案