【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;
}
原文地址:https://www.cnblogs.com/ganxiang/p/13544769.html