61. Rotate List
来源:互联网 发布:js数字滚动摇奖老虎机 编辑:程序博客网 时间:2024/06/03 15:05
#include <iostream>using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} };class Solution {public: ListNode* rotateRight(ListNode* head, int k) { if(!head) return head; int n=0; ListNode *temp=head; while(temp) { n++; temp=temp->next; } k=k%n; if(k==0) return head; int i=0; temp=head; while(1) { i++; if(i==n-k) break; temp=temp->next; } ListNode *returnptr=temp->next; temp->next=NULL; temp=returnptr; while(temp->next) { temp=temp->next; } temp->next=head; return returnptr; }};
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
- redis快速入门-进阶知识
- C++第四次作业
- 基于微信的分布式系统分析
- 定时器
- JQuery中2个等号与3个等号的区别
- 61. Rotate List
- c++第四次上机实验
- [C语言常见面试题]查询一个字符串中第一个只出现一次的字符,要求时间复杂度为O(1)
- LeetCode 290. Word Pattern
- struts2中的 ThreadLocal模式
- ORB特征点检测
- 这个离职原因一说出来就糟糕了!
- java取cpu、盘符和主板序列号
- Maven可继承的POM 元素