【leetcode】删除链表的节点

 

struct ListNode* deleteNode(struct ListNode* head, int val){
    int count = 0;
    struct ListNode* ret = head;
    struct ListNode* pre = head;
    while(head!=NULL)
    {
        count++;
        if (head->val == val && count != 1)
        {
            pre->next = head->next;
            return ret;
        }
        else if(head->val == val && count == 1)
        {
            return ret->next;
        }
        pre = head;
        head = head->next;
    }
    return ret;
}

 

posted @ 2020-08-22 11:05  温暖了寂寞  阅读(103)  评论(0编辑  收藏  举报