https://leetcode.com/problems/remove-linked-list-elements Easy

Решение

class Solution {
    fun removeElements(head: ListNode?, `val`: Int): ListNode? {
        val dummy = ListNode(0)
        dummy.next = head
        var prev = dummy
        var cur = head
        while (cur != null) {
            if (cur.`val` == `val`) prev.next = cur.next else prev = cur
            cur = cur.next
        }
        return dummy.next
    }
}