leetcode算法题--删除链表的节点

原题链接:https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/

ListNode* deleteNode(ListNode* head, int val) {
     
    ListNode *dummy = new ListNode(0);
    dummy->next = head;
    ListNode *p = dummy;
    while (p->next) {
     
        if (p->next->val == val) {
     
            p->next = p->next->next;
            break;
        }
        p = p->next;
    }
    return dummy->next;
}

你可能感兴趣的:(算法)