A tidy solution


  • 0
    S

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


Log in to reply
 

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