Skip to content

Commit 7273dc7

Browse files
authored
Merge pull request neetcode-gh#2429 from ColstonBod-oy/patch-2
Update 0206-reverse-linked-list.java
2 parents 0dd9c56 + 94c0e54 commit 7273dc7

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

java/0206-reverse-linked-list.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
class Solution {
44

55
public ListNode reverseList(ListNode head) {
6-
ListNode p = null;
7-
ListNode q = null;
8-
ListNode r = head;
9-
while (r != null) {
10-
p = q;
11-
q = r;
12-
r = r.next;
13-
q.next = p;
6+
ListNode current = head;
7+
ListNode previous = null;
8+
ListNode nextCurrent = null;
9+
10+
while (current != null) {
11+
nextCurrent = current.next;
12+
current.next = previous;
13+
previous = current;
14+
current = nextCurrent;
1415
}
15-
return q;
16+
17+
return previous;
1618
}
1719
}
1820

0 commit comments

Comments
 (0)