61. Rotate List
来源:互联网 发布:网络发票管理系统下载 编辑:程序博客网 时间:2024/06/05 03:39
方法1:
链表首尾相连,将第len个节点的下一个节点设为NULL即可,返回第len+1个节点
class Solution {public: ListNode* rotateRight(ListNode* head, int k) { if(head==NULL||head->next==NULL) return head; int len=1; ListNode* tail=head,*pre=head; while(tail->next) { tail=tail->next; len++; } k=k%len; k=len-k; while(k>1) { pre=pre->next; k--; } tail->next=head; head=pre->next; pre->next=NULL; return head; } };
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
- Android 热修复
- java编程思想--接口
- 自己封装用的Struts2BaseAction
- 修改dg备库错误路径名的数据文件
- 简单理解View的onMeasure过程
- 61. Rotate List
- cas ajax+jsonp+iframe 实现无页面跳转
- linux下配置jdk环境变量的几种常用方法
- 《iOS应用安全攻防实战》读书笔记(一)
- springMVC发送POST请求时接收不到参数问题
- 运动学与雅可比矩阵举例
- Jmeter Log on
- phpstorm 4.0 部署Web应用
- jpeg error #42