Remove Nth Node From End of List
很简单的一道题,隐含条件要问清楚, n> len的时候就删除首个
public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(head==null) return null; ListNode walk = head; ListNode run =head; for(int i=0; i<n; i++){ run = run.next; } if(run==null) return head.next; // 这个隐含条件要问清楚 while(run.next!=null){ run = run.next; walk=walk.next; } walk.next = walk.next.next; return head; } }