61. Rotate List【M】【54】【leetcode】
来源:互联网 发布:unity3d退出游戏代码 编辑:程序博客网 时间:2024/06/07 02:44
Given a list, rotate the list to the right by k places, where k is non-negative.
For example:
Given 1->2->3->4->5->NULL
and k = 2
,
return 4->5->1->2->3->NULL
.
Subscribe to see which companies asked this question
先算出list的长度,然后再用最朴素的想法来完成
class Solution(object): def rotateRight(self, head, k): if k == 0 or head == None: return head if not head.next: return head h = head l = 0 while h: l += 1 tail = h h = h.next #print l k = k % l if k == 0: return head count = 0 h = head new_h = ListNode(0) while count < l - k: prv = h h = h.next count += 1 new_h.next = h tail.next = head prv.next = None return new_h.next
0 0
- 61. Rotate List【M】【54】【leetcode】
- [LeetCode]61.Rotate List
- LeetCode --- 61. Rotate List
- [Leetcode] 61. Rotate List
- [leetcode] 61.Rotate List
- [leetcode] 61. Rotate List
- leetcode 61. Rotate List
- LeetCode 61. Rotate List
- [leetcode] 61. Rotate List
- 61. Rotate List LeetCode
- leetcode 61. Rotate List
- LeetCode 61. Rotate List
- leetcode 61. Rotate List
- [LeetCode]61. Rotate List
- LeetCode 61. Rotate List
- LeetCode *** 61. Rotate List
- LeetCode 61. Rotate List
- [Leetcode]61. Rotate List
- 解密Animate.css之CSS3动画实现方式大全源码(6星级)
- 使用VS GDB扩充套件在VS上远端侦错Linux上的C/C++程序
- 注入攻击-SQL注入和代码注入
- YCSB扩展-语句执行频率,执行指定的测试查询语句
- sql 联合查询
- 61. Rotate List【M】【54】【leetcode】
- Android Fragment 真正的完全解析(下)
- maven 常用命令
- QT格式化代码快捷键
- chrome的渲染算法确实有点屌
- 模型简化
- error C2065: “GWL_HINSTANCE”: 未声明的标识符
- 菜鸟成长记-各种奇葩错误总结
- Android线程通信机制,handler,looper,messageQueue的关系