203. Remove Linked List Elements 发表于 2021-12-22 递归12345678910class Solution { public ListNode removeElements(ListNode head, int val) { if (head == null) { return null; } head.next = removeElements(head.next, val); return head.val == val ? head.next : head; }} 迭代123456789101112131415class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummyHead = new ListNode(-1, head); ListNode curr = dummyHead; while (curr.next != null) { if (curr.next.val == val) { curr.next = curr.next.next; } else { curr = curr.next; } } return dummyHead.next; }} Reference203. Remove Linked List Elements