)
解题思路快慢指针不能return head是因为head可能被删除class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode dummy new ListNode(-1); dummy.next head; ListNode fast dummy; ListNode slow dummy; for (int i 0; i n; i) { fast fast.next; } while (fast.next ! null) { fast fast.next; slow slow.next; } slow.next slow.next.next; return dummy.next; } }