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)的更多相关文章

  1. 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. ...

  2. 【LeetCode】61. Rotate List 解题报告(Python)

    [LeetCode]61. Rotate List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

  3. Leetcode#61 Rotate List

    原题地址 我一直不太理解为什么叫rotate,翻译成"旋转"吧,似乎也不像啊.比如: 1->2->3->4->5->NULL 向右旋转2的距离,变成了 ...

  4. 61. Rotate List

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...

  5. [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 ...

  6. 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 ...

  7. 【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 ...

  8. 【一天一道LeetCode】#61. Rotate List

    一天一道LeetCode系列 (一)题目 Given a list, rotate the list to the right by k places, where k is non-negative ...

  9. [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 ...

随机推荐

  1. Redis事务及锁应用

    Redis只支持简单的事务,不像mysql那样比较完整严格,对数据的完整性也维持的很好.redis的开启事务实际上只是将开启事务之后的一段命令用队列包裹起来了,当调用redis的执行命令(exec)全 ...

  2. dateframe行列插入和删除操作

    ar = np.array(list("ABCDEFG")) # array只是Convert,默认会copy源值.asarray也是Convert,如果源值是array则不cop ...

  3. sourceTree 添加 ssh key 方法【转】

    1.使用 git 客户的生成公私钥:id_rsa.id_rsa.pub 1.1设置Git的user name和email: $ git config --global user.name " ...

  4. HotSpot Stop-and-Copy GC

    rednaxelafx的Cheney算法的伪代码.如果不用forwarding的话,维护一个旧地址到新地址的映射也可以. 其中重点部分: void Heap::collect() { // The f ...

  5. waitpid()设置WNOHANG位(非阻塞模式)判断子进程的状态是否有所改变

    参考<Linux/Unix系统编程手册>26.1.5,对于系统调用waitid() #include <sys/wait.h> int waitid(idtype_t idty ...

  6. 洛谷八连测R4

    1.逃避 https://www.luogu.org/problemnew/show/T14561 注意: 1.输入时需要用EOF判断,否则会TLE. 2.用flag判断字符是不是每一句首字母. 3. ...

  7. Jquery each循环中中断

    在each代码块内不能使用break和continue,要实现break和continue的功能的话,要使用其它的方式 break----用return false; continue --用retu ...

  8. 关于千兆以太网芯片及VLAN浅析

    MARVEL出产的高端千兆以太网交换芯片,对每个端口支持不同的交换模式. 包括4种模式: Secure模式:所带VLAN tag必须存在于VTU表中,且入端口必须是该VLAN成员,否则丢弃报文. Ch ...

  9. var与Javascript变量隐式声明

    在JavaScript中,var用来声明变量,但是这个语法并不严格要求,很多时修改,我们可以直接使用一个变量而不用var声明它.var x = "XX"; y ="xxx ...

  10. [转]第一次使用Android Studio时你应该知道的一切配置(三):gradle项目构建

    目录: 1.gradle的概念 2.gradle配置jar包,和libs文件夹导入jar包的区别 3.签名打包: (1)Studio (2)命令行 (3)gradle wrapper的原理 4.Bui ...