/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteNode(ListNode* head, int val) {
//leetcode这道题限制不能删除节点
ListNode *vir_head = new ListNode(-1, head);
vir_head->next = head;
ListNode *cur = vir_head;
while (cur->next != nullptr) {
if (cur->next->val == val) {
ListNode *aux = cur->next;
cur->next = cur->next->next;
aux->next = nullptr;
}
else
cur = cur->next;
}
return vir_head->next;
}
};
10-12
598
10-12
274
10-18
749
10-14
229
10-13
403
10-12
1100