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

Let's Develop Together!
Download Telegram
image_2022-07-04_00-03-42.png
40.6 KB
#medium
#N19. Remove Nth Node From End of List
problem link
#solution
class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode start = new ListNode();
ListNode slow=start, fast=start;
start.next=head;
while(n-- +1 >0){
fast=fast.next;
}

while(fast!=null){
fast=fast.next;
slow=slow.next;
}
slow.next=slow.next.next;
return start.next;
}
}
👍2