Algorithms—61.Rotate List
来源:互联网 发布:客户地图软件 编辑:程序博客网 时间:2024/06/11 23:31
思路:找到断点,打断拼接。
/** * 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 head;} ListNode l=head; List<ListNode> list=new ArrayList<ListNode>(); while (l!=null) {list.add(l);l=l.next;} k=k%list.size(); if (k==0) {return head;} list.get(list.size()-k-1).next=null; list.get(list.size()-1).next=head; return list.get(list.size()-k); }}
耗时:324ms,中上游
0 0
- Algorithms—61.Rotate List
- Algorithms—189.Rotate Array
- Algorithms—48.Rotate Image
- 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
- 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
- C 的 "%s"对应以'\0'结尾的字符串
- Git命令参考手册(文本版)
- If We Were a Child Again
- Petrel 2014 图形工作站应用方案
- linux内核分析笔记----中断和中断处理程序
- Algorithms—61.Rotate List
- Oracle 列转行函数 Listagg()示例
- ftp error "425 Use PORT or PASV first."
- Num 16: HDOJ: 题目1061 : Rightmost Digit [ 求个位数 ] [ 快速幂算法 ]
- Android利用Fiddler进行网络数据抓包
- 返回函数的JavaScript函数
- Android笔记之:App模块化及工程扩展的应用
- Java安全(加密、摘要、签名、证书、SSL、HTTPS)
- Android 开发之:Intent.createChooser() 妙用