标签:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode dumy = new ListNode(0);//建立一个不用的头。。。然后真正的头在next里面,减少对头的处理 dumy.next = head; ListNode p = dumy; ListNode q = dumy; 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 dumy.next; } }
LeetCode--Remove Nth Node From End of List
标签:
原文地址:http://blog.csdn.net/wj512416359/article/details/42060869