标签:删除 link turn move while val tco int 元素
地址:https://leetcode-cn.com/problems/remove-linked-list-elements/
大意:删除链表中等于给定值的所有节点。
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
if(head == NULL)
return head;
ListNode *hh = new ListNode(0);
hh->next = head;
ListNode *newNode = hh;
while(newNode != NULL && newNode->next != NULL){
if(newNode->next->val == val){
newNode->next = newNode->next->next;
}else{
newNode = newNode->next;
}
}
return hh->next;
}
};
标签:删除 link turn move while val tco int 元素
原文地址:https://www.cnblogs.com/c21w/p/12683523.html