The Dream Of leozp

try my best

Leetcode: Remove Nth Node From End of List

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
   struct ListNode *first=head;
struct    ListNode *end=head;
    while(n--){
        end=end->next;
    }
    if(end==NULL){
        return head->next;
    }
    while(end->next!=NULL){
        first=first->next;
        end=end->next;
    }
    first->next=first->next->next;
    return head;
}

阅读更多
版权声明:本文为博主原创文章,欢迎指教~ https://blog.csdn.net/u013712847/article/details/52386572
文章标签: leetcode
个人分类: leetcode
上一篇Leetcode: 4Sum
下一篇Leetcode: Merge Two Sorted Lists
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭