Easy 1ms Java solution


  • 0
    S

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


  • 0
    Z

    Not 1ms anymore


Log in to reply
 

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