Leetcode 19. Remove Nth Node From End of List(python)
2016-04-06 14:08
519 查看
链表操作,只能遍历一遍然后。
用双指针
用双指针
# 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 """ left=right=head for i in range(n): right=right.next if right is None: return head.next #special while right.next is not None: right=right.next left=left.next left.next=left.next.next return head
相关文章推荐
- Nodejs in Visual Studio Code 05.Swig+Bootstrap
- node.js入门小实例
- hadoop namenode又一次格式化以后hbase的hmaster进程启动后立即消失
- 让你的 Node.js 应用跑得更快的 10 个技巧
- nodeJS + webStrome
- NodeJS研究笔记:异步编程导致难以察觉的bug
- nodejs(二)
- LeetCode 24 Swap Nodes in Pairs
- aop的概念以及 cglib-nodep-2.1_3.jar第三方jia包动态代理使用
- node版本管理器nvm(服务器项目相关)
- LeetCode 237. Delete Node in a Linked List(删除链表中的一个节点)
- 初探nodeJS
- 关注nodejs mean和nw.js
- Delete Node in a Linked List
- nodejs(一)
- ( Leetcode 24) Swap Nodes in Pairs
- NodeJS 模块开发及发布详解
- module.export和export区别 nodejs
- Nodejs in Visual Studio Code 04.Swig模版
- nodejs渲染到页面的理解