We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 64a6fff commit 2bd71c4Copy full SHA for 2bd71c4
Algorithms Basics/Chapter 2. Linked List/206. Reverse Linked List.cs
@@ -1,3 +1,4 @@
1
+// iteration
2
public class Solution {
3
public ListNode ReverseList(ListNode head) {
4
ListNode pre = null, temp = null;
@@ -9,4 +10,15 @@ public ListNode ReverseList(ListNode head) {
9
10
}
11
return pre;
12
13
+}
14
+
15
+// recursion
16
+public class Solution {
17
+ public ListNode ReverseList(ListNode head) {
18
+ if (head == null || head.next == null) return head;
19
+ ListNode newHead = ReverseList(head.next);
20
+ head.next.next = head;
21
+ head.next = null;
22
+ return newHead;
23
+ }
24
0 commit comments