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...

【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
  • 157

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: 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, ...
  • wyc1230
  • wyc1230
  • 2012年02月29日 00:47
  • 712

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, ...

LeetCode Remove Nth Node From End of List

Q: Given a linked list, remove the nth node from the end of list and return its head. For exam...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Leetcode: Remove Nth Node From End of List
举报原因:
原因补充:

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