0
点赞
收藏
分享

微信扫一扫

203. Remove Linked List Elements

SDKB英文 2022-07-12 阅读 55
编程语言

 

 

​​203. Remove Linked List Elements​​

code

203. Remove Linked List Elements_其它

203. Remove Linked List Elements_其它_02

/**
* 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* cur = head, *pre;//
while(cur)
{
if(cur->val == val)
{
if(cur==head) { head = head->next; delete cur; cur = head; }//
else {pre->next = cur->next; delete cur; cur = pre->next;}//
}
else
{
pre = cur;//
cur = cur->next;
}
}
return head;
}
};

View Code

 

 

 

1. Leetcode_remove-linked-list-elements;

举报

相关推荐

0 条评论