Leetcode: Remove Nth Node From End of List

原创 2016年08月31日 16:43:18
/**
 * 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;
}

版权声明:本文为博主原创文章,欢迎指教~ 举报

相关文章推荐

LeetCode 第十九题 Remove Nth Node From End of List

一,问题描述 1,删除一个单链表末尾开始算起的第n个结点,然后返回该单链表。 2,例如: 输入: 1->2->3->4->5 其中n=2; 输出: 1->2->3->5; 3,解题思...

Remove Nth node from End of list--LeetCode

题目: Given a linked list, remove the nth node from the end of list and return its head. For examp...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

【LeetCode】Remove Nth Node From End of List

题目介绍: 下面给出两种算法: 算法一

[leetcode: Python]19. Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head.For example,Given ...
  • NXHYD
  • NXHYD
  • 2017-05-19 08:28
  • 100

LeetCode#19. Remove Nth Node From End of List

题目:删除链表倒数第n个元素

LeetCode-19 Remove Nth Node From End of List(移除尾部第N个节点)

LeetCode-19 Remove Nth Node From End of List Given a linked list, remove the nth node from the end o...

LeetCode第19题之 Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head.For example,Given ...

LeetCode 19 — Remove Nth Node From End of List(C++ Java Python)

题目:http://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/ Given a linked list, remove t...

LeetCode 19. Remove Nth Node From End of List

19. Remove Nth Node From End of ListGiven a linked list, remove the nth node from the end of list an...

LeetCode: Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head. For example, ...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)