/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
ListNode *m, *h = new ListNode(0);
h->next = head;
m = h;
while(h->next != NULL){
if(h->next->val == val)
h->next = h->next->next;
else
h = h->next;
}
return m->next;
}
};
leetcode 203. Remove Linked List Elements
最新推荐文章于 2024-11-01 15:19:21 发布