Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2429 from ColstonBod-oy/patch-2
Browse files Browse the repository at this point in the history
Update 0206-reverse-linked-list.java
  • Loading branch information
a93a authored May 6, 2023
2 parents 0dd9c56 + 94c0e54 commit 7273dc7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions java/0206-reverse-linked-list.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
class Solution {

public ListNode reverseList(ListNode head) {
ListNode p = null;
ListNode q = null;
ListNode r = head;
while (r != null) {
p = q;
q = r;
r = r.next;
q.next = p;
ListNode current = head;
ListNode previous = null;
ListNode nextCurrent = null;

while (current != null) {
nextCurrent = current.next;
current.next = previous;
previous = current;
current = nextCurrent;
}
return q;

return previous;
}
}

Expand Down

0 comments on commit 7273dc7

Please sign in to comment.