remove-linked-list-elements
This commit is contained in:
parent
dbe344221b
commit
47b81f8c68
|
@ -0,0 +1,19 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
type ListNode struct {
|
||||||
|
Val int
|
||||||
|
Next *ListNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeElements(head *ListNode, val int) *ListNode {
|
||||||
|
top := &ListNode{Val: 0, Next: head}
|
||||||
|
last := top
|
||||||
|
for current := head; current != nil; current = current.Next {
|
||||||
|
if current.Val == val {
|
||||||
|
last.Next = current.Next
|
||||||
|
} else {
|
||||||
|
last = current
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return top.Next
|
||||||
|
}
|
Loading…
Reference in New Issue