19. Remove Nth Node From End of List

public class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode pre=new ListNode(0);
        pre.next=head;
        ListNode p=pre,q=pre;
        for(int i=0;i<n;i++)
            p=p.next;
        while(p.next!=null)
        {
            p=p.next;
            q=q.next;
        }
        q.next=q.next.next;
        return pre.next;
    }
}
原文地址:https://www.cnblogs.com/asuran/p/7578973.html