[LeetCode]Remove Linked List Elements
public class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; head = dummy; ListNode pre = dummy; ListNode p = pre.next; while (p != null) { if (p.val != val) { pre = p; p = p.next; } else { pre.next = pre.next.next; p = pre.next; } } return head.next; } }