Leetcode——删除链表的倒数第N个节点

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;
    }
原文地址:https://www.cnblogs.com/swqblog/p/13267352.html