LeetCode 19. Remove Nth Node From End of List
来源:互联网 发布:r软件怎么使用说明 编辑:程序博客网 时间:2024/04/29 18:30
题目:
Given a linked list, remove the nth node from the end of list and return its head.
For example,
Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
Try to do this in one pass.
删除已链表尾部开始的第n个节点
题解:
清楚python的链表结构就行,比较简单
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def removeNthFromEnd(self, head, n): """ :type head: ListNode :type n: int :rtype: ListNode """ i=1 res=[] temp=head while head.next != None: head=head.next i=i+1 j=1 while j<=i: if j==i-n+1: temp=temp.next j=j+1 else: res.append(temp.val) temp=temp.next j=j+1 return res
0 0
- 19. Remove Nth Node From End of List leetcode list
- [LeetCode]19.Remove Nth Node From End of List
- LeetCode 19. Remove Nth Node From End of List
- 19. Remove Nth Node From End of List Leetcode Python
- LeetCode --- 19. Remove Nth Node From End of List
- LeetCode 19.Remove Nth Node From End of List
- [Leetcode] 19. Remove Nth Node From End of List
- [leetcode] 19.Remove Nth Node From End of List
- <LeetCode OJ> 19. Remove Nth Node From End of List
- 19. Remove Nth Node From End of List LeetCode
- leetcode 19. Remove Nth Node From End of List
- [LeetCode OJ] 19. Remove Nth Node From End of List
- LeetCode 19. Remove Nth Node From End of List
- Leetcode:19. Remove Nth Node From End of List(JAVA)
- leetcode 19. Remove Nth Node From End of List
- Leetcode 19. Remove Nth Node From End of List
- 【LeetCode】19. Remove Nth Node From End of List
- leetcode 19.Remove Nth Node From End of List
- androd studio 依赖引用的方法以及常见的问题
- oracle 后台写sql 日期转换格式
- get、post、put、delete区别与含义
- 指南针开发(备忘)
- vim中读写特殊字符&回车和换行的区别
- LeetCode 19. Remove Nth Node From End of List
- document.ready和onload的区别——JavaScript文档加载完成事件
- Android运行时ART加载OAT文件的过程分析
- 213 lab2 bomb
- java设计模式,观察者模式
- Button上的文字自动变成大写的解决办法
- #368 –在Calendar 控件中指定不可选择日期(Specifying Blackout Dates in a Calendar Control)
- Java核心技术点之多线程
- jquery中使用ajax传递数组到webservice