easy


  • 0
    W
    class Solution {
        public ListNode removeElements(ListNode head, int val) {
            ListNode pre=new ListNode(-1);
            ListNode ret=pre;
            while(head!=null){
                if(head.val!=val) {
                	pre.next=head;
                	pre=pre.next;
                }
                head=head.next;
            }
            pre.next=null;
            return ret.next;
        }
    }
    

Log in to reply
 

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