61. Rotate List(易错)
来源:互联网 发布:蔡文静演过的网络剧 编辑:程序博客网 时间:2024/05/17 05:19
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
比如说 [1],1这样的数据。
class Solution {public:ListNode* rotateRight(ListNode* head, int k) {if (head == NULL||k<=0) return head;ListNode* p = head;int len = 0;while (p){p = p->next;len++;}k = k%len;///if (k == 0) return head;//ListNode* faster = head;ListNode* slower = head;while (k--){faster = faster->next;}while (faster->next){faster = faster->next;slower = slower->next;}ListNode* newHead = slower->next;slower->next = NULL;faster->next = head;return newHead;}};
0 0
- 61. Rotate List(易错)
- 61. Rotate List(python)
- 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
- 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
- Animation System Overview
- Java_泛型—generic
- SSH框架手动整合——Struts2+Hibernate4+Spring4
- gulp构建工具的几个使用技巧
- URAL 2067
- 61. Rotate List(易错)
- Laravel学习资源汇总
- css的命名规则
- pyqt4文档阅读(7.1):QPoint
- libev简介
- Java创建线程Thread的两个方法
- 内部类分析
- Android组件间通信--深入理解Intent与IntentFilter
- 在Raspberry上使用蓝牙4.0 BLE