标签:blog io java for div sp log on c
public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode firstTraveling = head; ListNode lastTraveling = head; for (int i=0; i<n; i++) { firstTraveling = firstTraveling.next; } if (firstTraveling==null) return head.next; while (firstTraveling.next != null) { firstTraveling = firstTraveling.next; lastTraveling = lastTraveling.next; } lastTraveling.next = lastTraveling.next.next; return head; } }
[LeetCode] Remove Nth Node From End of List
标签:blog io java for div sp log on c
原文地址:http://www.cnblogs.com/yuhaos/p/3967375.html