61. Rotate List(List)
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
.
class Solution {
public:
ListNode *rotateRight(ListNode *head, int k) {
if(!head) return head; ListNode *p = head;
ListNode *newHead;
int num = ;
while(p->next)
{
p = p->next;
num++;
}
k = k%num;
if(k==) return head;
p->next = head;
p = head;
for(int i = ; i<num-k-; i++)
{
p = p->next;
}
head = p->next;
p->next = NULL;
return head;
}
};
61. Rotate List(List)的更多相关文章
- 61. Rotate List(M);19. Remove Nth Node From End of List(M)
61. Rotate List(M) Given a list, rotate the list to the right by k places, where k is non-negative. ...
- 【LeetCode】61. Rotate List 解题报告(Python)
[LeetCode]61. Rotate List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
- Leetcode#61 Rotate List
原题地址 我一直不太理解为什么叫rotate,翻译成"旋转"吧,似乎也不像啊.比如: 1->2->3->4->5->NULL 向右旋转2的距离,变成了 ...
- 61. Rotate List
题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...
- [LeetCode] 61. Rotate List 解题思路
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- LeetCode OJ 61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- 【leetcode】61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- 【一天一道LeetCode】#61. Rotate List
一天一道LeetCode系列 (一)题目 Given a list, rotate the list to the right by k places, where k is non-negative ...
- [leetcode]61. Rotate List旋转链表
Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...
随机推荐
- PHP---如何修改域名的指定的根目录
如何修改域名的指定的根目录 环境:linux 使用工具:xShell 修改域名指定的文件根目录需要修改nginx的配置文件 第一步:连接xShell 第二步:进入根路径找到nginx的配置文件 cd ...
- bzoj1040(ZJOI2008)骑士——基环树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1040 基环树的模板. 套路就是把环断开,先把一端作为根节点,强制不选:再把另一端作为根节点, ...
- WCF引用方式之IIS方式寄宿服务
通过IIS方式寄宿服务 之前的例子是将控制台作为WCF的寄宿方式或者是直接添加契约项目的引用,然后通过配置或者是ChannelFactory的形式进行创建服务对象,其实在大多的开发中以IIS的形式创建 ...
- Spring Cloud Bus 消息总线 RabbitMQ
Spring Cloud Bus将分布式系统中各节点通过轻量级消息代理连接起来. 从而实现例如广播状态改变(例如配置改变)或其他的管理指令. 目前唯一的实现是使用AMQP代理作为传输对象. Sprin ...
- thinkphp中的配置与读取C方法详解
1.项目公共配置 Conf/config.php 内容如下 <?php /** *项目公共配置 *@package *@author **/ return array( 'LOAD_EXT_CO ...
- 安装windows 2003 server
最近去给客户安装windows 2003 server,想想也是技术,就写出来了,我这个实在虚拟机安装的,安装这个系统主要是为了安装limesurvey问卷系统 第一步:安装,选择Enter 第二步: ...
- Hibernate 一对一、一对多、多对多注解cascade属性的总结
作用:是否级联被注解字段里面的对象.可选值:javax.persistence.CascadeType.PERSIST, MERGE, REMOVE, REFRESH, DETACH, ALL.可选其 ...
- 在项目中redis做缓存的一些思路
首先,缓存的对象有三种: 1:数据库中单条的的数据(以表名跟id作为key永久保存到redis),在有更新的地方都要更新缓存(不适用于需要经常更新的数据): 2:对于一些不分页,不需要实时(需要多表查 ...
- 100.64.0.0/10运营商级(Carrier-grade)NAT保留IP地址
在一次跟踪路由的网络操作时发现自己路由器下一跳路由节点的IP地址比较奇怪,是100.64.0.1.好奇促使我查询了这个IP地址的归属,结果是保留地址,到这里觉得比较奇怪了,按照常理以IPv4为例保留的 ...
- 关于Trunk、Hybrid、Access、Tag、Untag、Pvid的关系
一.相关定义 1.Trunk口 Trunk口上可以同时传送多个VLAN的包,一般用于交换机之间的链接. 2.Hybrid口 Hybrid口上可以同时传送多个VLAN的包,一般用于交换机之间的链接或交 ...