Share my Javascript solution.


  • 0
    var removeElements = function(head, val) {
        var point = new ListNode(-1);
        var res = point;
        while (head !== null) {
            if (head.val !== val) {
                point.next = head;
                point = point.next;
            }
            head = head.next;
        }
        point.next = null;
        return res.next;
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.