Rotate List
来源:互联网 发布:淘宝html5 编辑:程序博客网 时间:2024/06/16 18:17
一、题目要求
Given a list, rotate the list to the right by k places, where k is non-negative.
For example:
Given 1->2->3->4->5->NULL
and k = 2
,
return 4->5->1->2->3->NULL
.
二、代码实现
ListNode* rotateRight(ListNode* head, int k) { ListNode* start=head,*p;int len=0;if(head==NULL||head->next==NULL)return head;while(start!=NULL){start=start->next;len++;}k=k%len;if(!k)return head;//start=head;p=head;while(k--)start=start->next;while(start->next!=NULL){start=start->next;p=p->next;}start->next=head;head=p->next;p->next=NULL;return head; }
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
- HDU 3657 Game(取数 最小割)经典
- Qt中多事件使用实例
- 用D3.js进行医疗数据可视化 (四) 堆积区图 (Stacked Area Chart)
- qsort 函数中的cmp
- 在linux上安装oracle(红帽) 前的检查工作
- Rotate List
- hadoop权威指南气象数据下载
- IOS - 会员信息提示
- 内部类
- vs2010 CString转换char *
- 网络拓扑图例库
- android 自定义viewR.styleable找不到或者是报错!
- 【转】常见数字IC设计、FPGA工程师面试题
- 分布式系统 缓存穿透与失效时的雪崩效应