【leetcode】Rotate List
来源:互联网 发布:彩霸王软件 编辑:程序博客网 时间:2024/06/05 19:00
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *rotateRight(ListNode *head, int k) { // Start typing your C/C++ solution below // DO NOT write int main() function if(head==NULL||head->next==NULL||k==0) return head; int len=0; ListNode *ptr=head,*tail=head; while(ptr!=NULL) { len++; tail=ptr; ptr=ptr->next; } k%=len; ptr=head; for(int i=1;i<=len-k-1;i++) { ptr=ptr->next; } tail->next=head; head=ptr->next; ptr->next=NULL; return head; }};
- [leetcode][list] Rotate List
- LeetCode: Rotate List
- LeetCode Rotate List
- LeetCode : Rotate List
- [Leetcode] Rotate List
- [LeetCode] Rotate List
- [leetcode] Rotate List
- leetcode 70: Rotate List
- [Leetcode] Rotate List
- 【leetcode】Rotate List
- [LeetCode]Rotate List
- [leetcode]Rotate List
- LeetCode-Rotate List
- [leetcode] Rotate List
- LeetCode - Rotate List
- LeetCode:Rotate List
- LeetCode 61: Rotate List
- leetcode之Rotate List
- HDU 4751 Divide Groups
- python 编码问题
- 华为一道机试题
- 小明的调查作业 nyist48
- 黑马程序员--Java学习笔记之面向对象思想(多态、内部类、匿名内部类、异常类)
- 【leetcode】Rotate List
- linux 下 android 源码下载 (repo sync)
- Hibernate createSQLQuery与createQuery的区别
- HDU 4750(Count The Pairs)
- 为什么我认为goroutine和channel是把别的平台上类库的功能内置在语言里
- Ecshop微博登录方式与用户账号的绑定
- android 圆角边框及图片
- 十二五中国电信宽带战略解析(三):规模与效益
- Crack the code interview_Q1.2