/**
* 移除倒数第n个节点
* @param node
* @param n
* @return
*/
public static Node removeNode(Node node,int n){
if(null == node || n<=0){
return node;
}
Node temp = node;
for (int i = 0; i <n ; i++) {
if(null == temp.next){
return temp;
}
temp = temp.next;
}
Node slow = node;
while (temp !=null && temp.next!=null){
temp = temp.next;
slow = slow.next;
}
slow.next = slow.next.next;
return node;
}
网友评论