@cxm-2016
2016-12-25T22:57:24.000000Z
字数 304
阅读 2328
算法
版本:1
作者:陈小默
思路:通过两个指针实现
fun <T> delete(node: Node<T>, value: T): Node<T>? {
var head: Node<T>? = node
while (head != null) {
if (head.value != value) break
head = head.next
}
if (head == null) return null
var pre = head
var cur = pre.next
while (cur != null) {
if (cur.value == value)
pre!!.next = cur.next
else
pre = cur
cur = cur.next
}
return head
}