Rotate List
来源:互联网 发布:淘宝包包店铺名字大全 编辑:程序博客网 时间:2024/04/29 08:46
做个circle ,看讨论来的
关键是怎么找到从哪里切,最后个循环的条件 len - k%len
public class Solution { public ListNode rotateRight(ListNode head, int k) { if(head==null || head.next == null ||k==0) return head; ListNode n = head; int len = 1; while(n.next!=null) { n = n.next; len++; } n.next = head; ListNode pre = n; n = n.next; for(int i=0; i< len-k%len; i++){ n = n.next; pre = pre.next; } pre.next = null; return n; }}
0 0
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- rotate-list
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- 用户角色分组使用license
- Sicily 1754. 逃离洞穴
- 数据结构复习—C++实现静态顺序表
- 实例详解Linux下MySQL数据库性能调优方法
- 内部排序算法
- Rotate List
- 强大的分组SectionListView, 支持自定义组头布局和分组的内容布局, 组头有挤压效果
- 3、求100-1000之间的水仙花数。(水仙花数,是指一个三位数,它的各位数字的立方和等于自身数,例:153=13+53+33)
- 关于matlab的编译问题--出现找不到指定模块C:MATLAB7\bin\win32\atlas_Athlon.dll
- Linux的网络编程面试题汇总
- MapReduce论文中文翻译
- Sicily 1729. Steganography
- git 命令行 使用指南
- (转)关于内存池使用时机