Easy To Understand 7-line Java Solution


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

Log in to reply
 

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