public ListNode removeNthFromEnd(ListNode head, int n) { ListNode slow = head; ListNode fast = head; //快指针先走n-1步 int i = 1; while(i <= n) { fast = fast.next; i++; } // System.out.println(fast.val); if(fast == null) { return head.next; } while(fast.next != null) { slow = slow.next; fast = fast.next; } slow.next = slow.next.next; return head; }