Leetcode_19

来源:互联网 发布:socket编程是什么意思 编辑:程序博客网 时间:2024/06/06 00:24


/** * Definition for singly-linked list. * struct ListNode { *     int val; *     struct ListNode *next; * }; */struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {    int count = 0;    int count_1 = 0;    struct ListNode* node = head;    while(node){        ++ count;        node = node->next;    }    if(count < n)        return head;    if(count == n){        head = head->next;        return head;    }    node = head;    while(node){        ++count_1;        if(count - count_1 == n){            break;        }        node = node->next;    }    node->next = node->next->next;    return head;    }


0 0