LeetCode #19 Remove Nth Node From End of List
2015-07-23 11:57
429 查看
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # @param {ListNode} head # @param {integer} n # @return {ListNode} def removeNthFromEnd(self, head, n): q = p = head dis = 0 if head == None or (head.next==None and n==1): return None while dis != n+1 or q!= None: if dis>n: p=p.next dis-=1 if q != None: q = q.next dis+=1 if q == None and dis < n+1: return head.next if p.next != None: p.next = p.next.next return head
相关文章推荐
- Populating Next Right Pointers in Each Node
- nodejs之获取客户端真实的ip地址+动态页面中引用静态路径下的文件及图片等内容
- [Leetcode] Swap Nodes in Pairs
- NodeJS优缺点及适用场景讨论
- XmlNode中的Value值为空的问题
- [Leetcode 24, Medium] Swap Nodes in Pairs
- [Leetcode 117, Hard] Populating Next Right Pointers in Each Node II
- [Leetcode 116, Medium] Populating Next Right Pointers in Each Node
- [leedcode 117] Populating Next Right Pointers in Each Node II
- Remove Nth Node From End of List
- [leedcode 116] Populating Next Right Pointers in Each Node
- NodeJS开发者-资质分级评判标准
- Populating Next Right Pointers in Each Node II
- HTML DOM nodeName nodeValue
- [leetcode] Reverse Nodes in k-Group
- 使用Node.js+Socket.IO搭建WebSocket实时应用(聊天室)
- node.js 入门示例
- NodeJS中的事件
- datanode却没有启动
- datanode却没有启动