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. drill 试用

    1. 下载 http://drill.apache.org/ 2. 启动本地模式 bin/sqlline -u jdbc:drill:zk=local 3. 查询数据 select c.r_name ...

  2. Android源代码分析之拍照、图片、录音、视频和音频功能

    Android源代码分析之拍照.图片.录音.视频和音频功能   //选择图片 requestCode 返回的标识 Intent innerIntent = new Intent(Intent.ACTI ...

  3. 如何批处理多个MySQL文件

    @echo off CHCP 65001 --设置cmd编码for %%i in (E:\sql\*.sql) do (   --多个MySQL  SQL文件的存放目录echo excute %%i ...

  4. 开始创建一个 Vue 项目

    开始创建一个 Vue 项目 安装 nodejs 略 安装 npm 默认安装时自带了 npm 安装 cnpm 为了更快的下载组件,使用cnpm,cnpm 是淘宝前端的镜像. 使用 npm 安装 cnpm ...

  5. bzoj 1069 [SCOI2007]最大土地面积——旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1069 发现 n 可以 n^2 .所以枚举对角线,分开的两部分三角形就可以旋转卡壳了. 注意坐 ...

  6. C# 7.0 新特性收集

    1.out-variables(Out变量) 2.Tuples(元组) 3.Pattern Matching(匹配模式) 4.ref locals and returns (局部变量和引用返回) 5. ...

  7. STM32F4XX启动文件分析

    STM32F4XX启动文件分析 - STM32F4XX启动文件下载地址 导读:STM32F4XX启动文件的作用 初始化设置SP,即栈指针 初始化设置PC指针指向复位中断处理函数,即PC = Reset ...

  8. 数据库表数据传输到Oracle方案

    方案步骤为:数据导出到文件(增量或全量),通知接口文件就绪(上传到ftp或提供下载url),接收方下载文件,解析文件并入库.Oracle需要建立对应的临时表和正式表,入库步骤为:清空临时表,批量插入数 ...

  9. 可复用的自定义Adapter

    public abstract class MyAdapter<T> extends BaseAdapter { private ArrayList<T> mData; pri ...

  10. 怎么使用ping命令进行连通性测试

    关于ping命令的作用: ping 命令有助于验证网络层的连通性!一般进行网络故障排除时,可以使用ping 命令向目标计算机或IP地址发送ICMP回显请求,目标计算机会返回回显应答,如果目标计算机不能 ...