leetcode之Rotate List
来源:互联网 发布:淘宝做话费充值 编辑:程序博客网 时间:2024/05/21 22:54
原题如下:
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 == NULL || k == 0)return head;int n = 1;ListNode * p = head, *q = head, *tail = head;while(tail->next != NULL){ n++;tail = tail->next;}k = k % n;if(k == 0)return head;for(int i = 1; i < n - k; i++){ p = p->next;}q = p->next;p->next = NULL;tail->next = head;return q; }};
0 0
- leetcode之Rotate List
- LeetCode之Rotate List
- leetcode之Rotate List
- LeetCode之Rotate List
- leetcode之Rotate List
- 【Leetcode】之Rotate List
- leetcode:单链表之Rotate List
- Leetcode之Rotate List 问题
- [leetcode][list] Rotate List
- leetcode 之Rotate List 解题思路
- LeetCode 之 Rotate List — C 实现
- LeetCode进阶之路(Rotate List)
- LeetCode: Rotate List
- LeetCode Rotate List
- LeetCode : Rotate List
- [Leetcode] Rotate List
- [LeetCode] Rotate List
- [leetcode] Rotate List
- linux tomcat
- 二叉树的遍历
- UltraEdit不自动生成保存备份文件(.bak)
- 世界杯:一句顺其自然,里面包含了我多少绝望和不甘心
- 立体类族共有的抽象类
- leetcode之Rotate List
- 读流的方式取远程图片,再以流的方式显示在页面上
- C# 调试
- WinCE中,环境变量的添加,删除和查询
- 第十三周 程序阅读
- eclipse配置weblogic时,提示does not contain a valid WebLogic Server install
- 对象的创建过程(来自《java编程思想》)
- 学徒浅析Android开发:第六讲——屏幕分辨率自适应
- ARM C C++内存对齐