categories: DataStructure
/*** public class ListNode {* int val;* ListNode next;* ListNode(int x) { val = x; }* }*/
203. 移除链表元素
问题描述
问题分析
代码实现
class Solution {public ListNode removeElements(ListNode head, int val) {// 将整个链表想象成head+子链表if (head == null)return null;// 先处理子链表head.next = removeElements(head.next, val);// 再处理头结点return head.val == val ? head.next : head;}}
