Given the head of a linked list and a value, remove all nodes containing the value.
var prev = head var cur = head?.next while cur != nil { while cur != nil && cur?.value == value { cur = cur?.next } prev?.next = cur prev = cur cur = cur?.next } if head?.value == value { head = head?.next }