leetcode-剑指18-OK

language: C

address

// 憨憨题,不解释
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* deleteNode(struct ListNode* head, int val){
    if(head->val == val)
        return head->next;
    struct ListNode* p =head->next;
    struct ListNode* pre =head;
    while(p->val !=val){
        pre = p;
        p = p->next;
    }
    pre->next = p->next;
    return head;
}
posted @ 2021-01-25 09:28  RougeBW  阅读(54)  评论(0编辑  收藏  举报