61. Rotate List
来源:互联网 发布:qq活动抽奖软件 编辑:程序博客网 时间:2024/06/04 19:52
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.
class Solution {public: ListNode* rotateRight(ListNode* head, int k) { if(!head) return head; int len = 1; ListNode *newH = head, *tail = head; while(tail->next){ len++; tail = tail->next; } tail->next = head ; //****cricle the link if(k %= len){ while(len-k){ tail = tail->next; k++; } } newH = tail->next; tail->next = NULL; return newH; }};
0 0
- [LeetCode]61.Rotate List
- 61. Rotate List
- LeetCode --- 61. Rotate List
- [Leetcode] 61. Rotate List
- 61. Rotate List
- [leetcode] 61.Rotate List
- [leetcode] 61. Rotate List
- 61. Rotate List
- leetcode 61. Rotate List
- LeetCode 61. Rotate List
- [leetcode] 61. Rotate List
- 61. Rotate List
- 61. Rotate List
- 61. Rotate List LeetCode
- leetcode 61. Rotate List
- 61. Rotate List
- 61. Rotate List
- 61. Rotate List
- Educational Codeforces Round 16 E. Generate a String (dp)
- Android NDK编程
- 对ssh中struts、spring、hibernate分工的理解
- <1>黑电平
- 设计模式学习之路-策略模式
- 61. Rotate List
- mongodb安装
- 单词拼接(有向图的欧拉回路)
- Binary Tree Level Order Traversal
- 反编译apk文件,获取strings.xml文件的内容——使用apktool反编译
- hdu 1534 简单差分约束
- android vitamion
- 判断map中的value是否为空
- Ubuntu开启Samba服务,并通过windows系统映射共享目录