标签:ret node this while ext 错误 spec 删除 pre
/**
* 在单向链表中删除指定的key
*/
public class RemoveSpecKeyFromNode {
public static class Node<T> {
public T value;
public Node next;
public Node(T node) {
this.value = node;
}
}
public static <T> Node removeSpecKeyFromNode(Node node, T key) {
if (node == null || key == null) {
return node;
}
while (node.value == key) {
node = node.next;
}
Node pre = node;
Node cur = null;
while ((cur = node.next) != null) {
if (cur.value == key) {
pre.next = cur.next;
} else {
pre = cur;
}
}
return node;
}
}
/* 如有错误,欢迎批评指正 */
标签:ret node this while ext 错误 spec 删除 pre
原文地址:https://www.cnblogs.com/laydown/p/12791241.html