链接:https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/submissions/
/** * 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) { if (head->val == val) return head->next; ListNode* ret = head; while (ret->next->val != val) ret = ret->next; ret->next = ret->next->next; return head; } };
原文:https://www.cnblogs.com/clown9804/p/12340429.html