Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public ListNode removeNthFromEnd(ListNode head, int n) {
- ListNode start = new ListNode(-1);
- ListNode slow = start;
- ListNode fast = start;
- slow.next = head;
- for (int i = 0; i < n + 1; i++) {
- fast = fast.next;
- }
- while (fast != null) {
- slow = slow.next;
- fast = fast.next;
- }
- slow.next = slow.next.next;
- return start.next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement