题解 | #删除链表的倒数第n个节点#
删除链表的倒数第n个节点
http://www.nowcoder.com/practice/f95dcdafbde44b22a6d741baf71653f6
public ListNode removeNthFromEnd (ListNode head, int n) { if(head == null) return null; ListNode temHead = new ListNode(-1); temHead.next = head; ListNode p = temHead, q = temHead; int count = n; while(count > 0){ q = q.next; count --; } while(q.next != null){ q = q.next; p = p.next; } if(p.next != null) p.next = p.next.next; else p.next = null; return temHead.next; }