problem description:
  remove the nth node from the end of the list

for example:

  given: 1->2->3  n = 1

  return: 1->2

thought:

  first:you should know the length

  second:if the del node is the  first node ,just return head.next;esle find the prior node of the del node

  third: use a node record the prior node,and make the node.next = del.node.next

  last:return head

there is my python solution:

# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None class Solution(object):
def removeNthFromEnd(self, head, n):
"""
:type head: ListNode
:type n: int
:rtype: ListNode
"""
i = 0
first = head
while first:
i += 1
first = first.next
first=head
if i-n==0:
return head.next
j = 0
while j<i-n-1:
first = first.next
j += 1
second = first
first = first.next
second.next = first.next
return head

it can beat 78% python users

remove the nth node from the end of the list的更多相关文章

  1. [LeetCode] Remove Nth Node From End of List 移除链表倒数第N个节点

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

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

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

  4. No.019: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, ...

  5. 【leetcode】Remove Nth Node From End of List(easy)

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

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

  7. 63. Swap Nodes in Pairs && Rotate List && Remove Nth Node From End of List

    Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exam ...

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

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

  9. LeetCode: Remove Nth Node From End of List 解题报告

    Remove Nth Node From End of List Total Accepted: 46720 Total Submissions: 168596My Submissions Quest ...

随机推荐

  1. 多进程log4cxx区分日志

    多进程log4cxx区分日志 (金庆的专栏) 网游客户端一般会多开,多个进程会写同一个日志文件.log4cxx看来会对文件加锁,防止多进程写同一文件写乱,截止目前还没发现错乱的日志. log4cxx有 ...

  2. (三十)PickerView文字和随机数的使用

    PickerView用于展示供选择的内容(例如日期选取.点菜等). 有三种情况: 1.每一列都是独立的选取 2.右边的列受到左边列的影响 3.包含图片 PickerView和TableView类似,通 ...

  3. libevent之Reactor模式

    通过前边的一篇博文轻量级网络库libevent初探,我们知道libevent实际上是封装了不同操作系统下的/dev/poll.kqueue.event ports.select.poll和epoll事 ...

  4. 《java入门第一季》之面向对象(方法重写问题)

    方法重载的引入:根据一个案例: /* 继承中成员方法的关系: A:子类中的方法和父类中的方法声明不一样,这个太简单. B:子类中的方法和父类中的方法声明一样,这个该怎么玩呢? 通过子类对象调用方法: ...

  5. iOS和OS X中的bundle

    bundle也可以称之为包(package). 它在iOS和OS X中实际为一个文件夹但却当成单独的文件来对待. 每一个app都有一个bundle,并且你可以通过在xxx.app图标上右击鼠标然后选择 ...

  6. linux内核算法---hex_to_bin分享

    这是我从内核抠出来的一段代码,用处就是传入一个字符,即可以用printf语句%d以十进制数的格式输出,同时也可以以%p地址的形式输出. 代码如下: #include <stdio.h> # ...

  7. EBS R12安装升级(FRESH)(四)

    7 升级Oracle数据库到11gR2 7.1 先打补丁7303030_zhs,9062910,8919489,8919489_ZHS ,9868229,10163753,11071569,97380 ...

  8. 数据结构---栈C语言实现

    #include <stdio.h> #include <stdlib.h> #define uchar unsigned char #define uint unsigned ...

  9. javascript内置对象速查(一)

    字符串对象 var str = new String("Hello World"); 可以调用其中的一些方法: str.length str.big 日期对象 var dt = n ...

  10. CSS3概述

    首先我们了解下什么是css3,css3是css技术的一个升级.css3中并没有采用总体结构,而是采用分工协作的模块化结构. css3中的模块 模块名称 功能描述 basic box model 定义各 ...