public class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
if (head == null || n==0) return null;
ListNode listNode = new ListNode(0);
listNode.next = head;
ListNode p = listNode;
ListNode q = listNode;
for (int i=0; i<n; i++){
if (p.next != null) p = p.next;
else return head;
}
while (p.next!=null){
p = p.next;
q = q.next;
}
ListNode tmp = q;
q.next = q.next.next;
return listNode.next;
}
}
09-15
09-15