My Java Solution


  • 1
    A

    public class Solution {

    public ListNode removeElements(ListNode head, int val) {
        ListNode start = new ListNode(0);
        ListNode node = head, prev = start;
        start.next = head;
        while(node!= null) {
            if (node.val == val) prev.next = prev.next.next;
            else prev = prev.next;
            node = node.next;
        }
        return start.next;
    }
    

    }


Log in to reply
 

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