203. 移除链表元素

老题新做
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
if(!head) return nullptr;
if(head->val != val){
head->next = removeElements(head->next, val);
}else{
ListNode* temp = head->next;
delete head;
return removeElements(temp, val);
}
return head;
}
};

浙公网安备 33010602011771号