Skip to content

Commit 94c0e54

Browse files
Update 0206-reverse-linked-list.java
Made the variable names more descriptive for the iterative solution.
1 parent f0c5939 commit 94c0e54

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)