Closed underwindfall closed 2 years ago
https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/
思路
[x] 刷15mins
[x] 刷5mins
// time O(n) // space O(1) class Recursive { public ListNode reverseList(ListNode head) { if (head == null || head.next == null) { return head; } ListNode next = reverseList(head.next); head.next.next = head; head.next = null; return next; } } //time O(n) //space O(1) class DummyNode { public ListNode reverseList(ListNode head) { ListNode dummy = new ListNode(-1); while (head.next != null) { ListNode next = head.next; head.next = dummy.next; dummy.next = head; head = next; } return dummy.next; } }
https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/
思路
[x] 刷15mins
[x] 刷5mins