19. Remove Nth Node From End of List

原创 2016年06月01日 18:33:15
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
         if(head == NULL || head->next == NULL)  
        return NULL;  
    ListNode * first = head;  
    ListNode * second = head;  
    for(int i = 0;i < n;i++)  
        first = first->next;  
    if(first == NULL)  
        return head->next;  
    while(first->next != NULL)  
    {  
        first = first->next;  
        second = second->next;  
    }  
    second->next = second->next->next;  
    return head;  
    }
};

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

[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
  • 126

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

LeetCodet题解--19. Remove Nth Node From End of List(删除链表的倒数第n个元素)

链接 LeetCode题目:https://leetcode.com/problems/remove-nth-node-from-end-of-list GitHub代码:https:/...

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笔记: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 of list and return its head. For example, ...

[C++]LeetCode 19: Remove Nth Node From End of List(删除链表中倒数第n个节点)

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

Leetcode_19_Remove Nth Node From End of List

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41778305 Given a linked list, ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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