Java 2ms Solution


  • -2
    P
    public ListNode removeElements(ListNode head, int val) {
        ListNode copy=head;
        while(copy!=null&copy.val==val){
            copy=copy.next;
        }
        head=copy;
        while(copy!=null&copy.next!=null){
            if(copy.next.val==val){
                copy.next=copy.next.next;
            }else{
              copy=copy.next;
            }
        }
        return head;
    }

  • 0
    A
    This post is deleted!

Log in to reply
 

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