Rotate List
来源:互联网 发布:scientific linux 6 编辑:程序博客网 时间:2024/06/05 04:21
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode rotateRight(ListNode head, int k) { if (head == null) { return null; } int length = 1; ListNode dummy = new ListNode(-1); dummy.next = head; while (head.next != null) { head = head.next; length++; } int shift = k % length; if (shift <= 0) { return dummy.next; } ListNode ptr = dummy; for (int i = 0; i < (length - shift); i++) { ptr = ptr.next; } head.next = dummy.next; dummy.next = ptr.next; ptr.next = null; return dummy.next; }}
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
- 仿大众点评下拉菜单实现
- java 判断一个字串中的字符全是字母
- web 应用内存溢出问题
- JSON.parse()与JSON.stringify() (浏览器兼容性:IE8以上、Chrome、Firefox3.5、Opera10.5、Safari4.0)
- OpenCV使用标定图
- Rotate List
- iOS开发系列--让你的应用“动”起来--动画
- Android SnackBar:你值得拥有的信息提示控件
- 欢迎使用CSDN-markdown编辑器
- ThreadLocal
- Tomcat + JPA多数据源实现
- toj3860
- Mybatis中<choose> 的使用方法
- android:showAsAction用法