Skip to content

Commit 08066df

Browse files
Create 206. Reverse Linked List.java
1 parent ed259ed commit 08066df

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

java/206. Reverse Linked List.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//Use three pointers and so you can change the next of the mid to the first one without losing the track of the original left.
2+
class Solution {
3+
public ListNode reverseList(ListNode head) {
4+
ListNode p = null;
5+
ListNode q = null;
6+
ListNode r = head;
7+
while (r!=null) {
8+
p = q;
9+
q = r;
10+
r = r.next;
11+
q.next = p;
12+
}
13+
return q;
14+
}
15+
}

0 commit comments

Comments
 (0)