Leetcode in Java && Oracle
419 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-14_00-34-17.png
38.2 KB
#N206. Reverse Linked List
problem link

#solution
class Solution {
public ListNode reverseList(ListNode head) {
if(head==null||head.next==null) return head;
ListNode prev=null, curr=head, after=head.next;

while(curr.next.next!=null){
curr.next=prev;
prev=curr;
curr=after;
after=after.next;
}

curr.next=prev;
after.next=curr;

return after;
}
}