Remove Nth Node From End of List - LeetCode
来源:互联网 发布:好看的喜剧电影知乎 编辑:程序博客网 时间:2024/06/05 08:31
Remove Nth Node From End of List - LeetCode
题目:
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.
分析:
纯考验链表的题目。感觉一句话占用分析好坑啊。。
代码:
class Solution: # @return a ListNode def removeNthFromEnd(self, head, n): l,l1,prev = head,head,head count,i = 0,0 while head: count += 1 head = head.next if count-n == 0: l1 = l.next return l1 while l: if i == count - n: prev.next = l.next return l1 i+=1 prev,l = l,l.next
0 0
- LeetCode[Linked List]: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- leetcode 40: Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- Leetcode 19 Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- [LeetCode]Remove Nth Node From End of List
- LeetCode-Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- LeetCode 19: Remove Nth Node From End of List
- LeetCode - Remove Nth Node From End of List
- LeetCode | Remove Nth Node From End of List
- leetcode之Remove Nth Node From End of List
- 数据库性能优化有哪些措施?
- CSS3选择器——1、基本选择器
- Coloring Brackets - CodeForces 149 D dp
- Java Arrays的10种最重要的方法
- 自学成才
- Remove Nth Node From End of List - LeetCode
- nagios插件之登陆路由器实现ping监控
- C语言实现二分法查找
- 实时监听UITextField内文字的改变
- Android运用Gradle build后生成的app-debug-unaligned.apk是什么?
- 2037,多想,多做。
- python中的交互执行函数
- 字符串的输出处理
- 227 - Puzzle