1. 题目原址
https://leetcode.com/problems/remove-linked-list-elements/+
2. 题目描述
3. 题目大意
给定一个链表和一个值,将链表中的给定值节点删除。
4. 解题思路
- 签到题
5. AC代码
class Solution {
public ListNode removeElements(ListNode head, int val) {
if(head == null) return head;
if(head.val == val)
return removeElements(head.next,val);
ListNode pre = head,cur = head;
while(cur != null) {
if(cur.val == val)
pre.next = cur.next;
else
pre = cur;
cur = cur.next;
}
return head;
}
}