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. Python 函数 -xrange()

    xrange() xrange() 函数用法与 range 完全相同,所不同的是生成的不是一个数组,而是一个生成器. 语法: xrange(stop) xrange(start, stop[, ste ...

  2. vue-router做路由拦截时陷入死循环

    今天分享一下使用vue-router做路由拦截时遇到的坑. 需要提前了解的api 1:router.beforeEach( to , from ,next) ; to: Route: 即将要进入的目标 ...

  3. 军哥LNMP优化

    http://bbs.vpser.net/thread-8914-1-1.html http://www.zxsdw.com/index.php/archives/881/ 修改/usr/local/ ...

  4. (四)、Fiddler打断点

    一.打断点是Fiddler一个比较好用的功能,它可以做一些手工操作很难做的事情. 那为什么要打断点? 看下图,Fiddler打开后,Client(客户端)发送的请求会先经过Fiddler,然后Fidd ...

  5. angular-ui-bootstrap的弹出框定义成一个服务的实践(二)

    定义一个弹出框的服务:alert_box defiine(["app"],function(mainapp){ mainapp.controller('ModalInstanceC ...

  6. 读jQuery之二十(Deferred对象)--(转)

    原博文地址:http://www.cnblogs.com/snandy/archive/2012/12/19/2812935.html Deferred对象是由.Deferred构造的,.Deferr ...

  7. ThreadPoolExecutor之三:自定义线程池-扩展示例

    ThreadPoolExecutor是可扩展的,下面一个示例: package com.dxz.threadpool.demo1; import java.util.concurrent.Blocki ...

  8. 阻塞队列之四:ArrayBlockingQueue

    一.ArrayBlockingQueue简介 一个由循环数组支持的有界阻塞队列.它的本质是一个基于数组的BlockingQueue的实现. 它的容纳大小是固定的.此队列按 FIFO(先进先出)原则对元 ...

  9. IT运维的定义

      IT运维是IT管理的核心和重点部分,也是内容最多.最繁杂的部分,该阶段主要用于IT部门内部日常运营管理,涉及的对象分成两大部分,即IT业务系统和运维人员,该阶段的管理内容又可细分为七个子系统:   ...

  10. html5的canvas方法的总结

    canvas的方法 save()保存当前环境的状态 restore() 返回之前保存过的路径状态和属性 createEvent() getContext()返回一个对象,指出访问绘图功能必要的API ...