代码:

 #include<iostream>
#include<vector> using namespace std; struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
}; ListNode* rotateRight(ListNode* head, int k) {
if (head == NULL)
return head;
ListNode * p = head;
int i = ;
while (p->next != NULL)
{
p = p->next;
i++;
}
ListNode * tail = p;
int L = i;
cout << "L = " << L << endl;
k = L - k%L;
cout << "K = " << k << endl;
if (k == L)
return head;
i = ;
p = head;
while (i != k)
{
p = p->next;
i++;
}
cout << "p ="<<p->val << endl;
ListNode *newHead = p->next;
p->next = NULL;
tail->next = head;
return newHead;
} int main()
{
ListNode * head = new ListNode();
ListNode *p = head;
for (int i = ; i <= ; i++)
{
p->next = new ListNode(i);
p = p->next;
}
p = NULL;
for (ListNode * temp = head; temp != NULL; temp = temp->next)
cout << temp->val << endl;
ListNode * newHead = rotateRight(head, );
cout << "-----------------------------------------" << endl;
for (ListNode * temp = newHead; temp != NULL; temp = temp->next)
cout << temp->val << endl;
}

leetcode Submission Details的更多相关文章

  1. LeetCode——Submission Details

    Description: Given a string of numbers and operators, return all possible results from computing all ...

  2. Submission Details [leetcode] 算法的改进

    最先看到这一题,直觉的解法就是len从1到s1.size()-1,递归调用比較s1和s2长度为len的子串是否相等.以及剩余部分是否相等. 将s1分成s1[len + rest],分别比較s2[len ...

  3. 【leetcode】Submission Details

    Given two sentences words1, words2 (each represented as an array of strings), and a list of similar ...

  4. Submission Details

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  5. [LeetCode OJ] Max Points on a Line

    Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...

  6. [leetCode][012] Two Sum (1)

    [题目]: Given an array of integers, find two numbers such that they add up to a specific target number ...

  7. [leetCode][016] Add Two Numbers

    [题目]: You are given two linked lists representing two non-negative numbers. The digits are stored in ...

  8. leetcode 15. 3Sum 二维vector

    传送门 15. 3Sum My Submissions Question Total Accepted: 108534 Total Submissions: 584814 Difficulty: Me ...

  9. [sqoop1.99.6] 基于1.99.6版本的一个小例子

    1.创建mysql数据库.表.以及测试数据mysql> desc test;+-------+-------------+------+-----+---------+------------- ...

随机推荐

  1. Hbase 参数配置及优化

    From:http://www.open-open.com/lib/view/open1346684547787.html 接触hbase已有半年的时间,查了很多资料,也参考了很多别人心得,也希望把自 ...

  2. Flex布局(转载)

    网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂 ...

  3. 从JVM的角度解析String

    1. 字符串生成过程 我们都知道String s = "hello java";会将“hello java”放入字符串常量池,但是从jvm的角度来看字符串和三个常量池有关,clas ...

  4. shell编程中用户输入处理(shell 04)

    shell编程中用户输入处理1.命令行参数2.脚本运行时获取输入 命令行参数 通过空格来进行分割的位置参数 :$+position $0,$1,$2 ....$0 :程序名$1,$2,$3 ... $ ...

  5. jmeter 打不开 提示“Not able to find Java executable or version”的解决办法

    Not able to find Java executable or version. Please check your Java installation . errorlevel=2Not a ...

  6. python开发模块基础:异常处理&hashlib&logging&configparser

    一,异常处理 # 异常处理代码 try: f = open('file', 'w') except ValueError: print('请输入一个数字') except Exception as e ...

  7. ffmpeg码率控制

    一.VBR与CBR的含义和区别 VBR是动态码率.CBR是静态码率. VBR(Variable Bitrate)动态比特率.也就是没有固定的比特率,压缩软件在压缩时根据音频数据即时确定使用什么比特率, ...

  8. python的ftplib模块

    Python中的ftplib模块 Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件 FTP的工作流程及基本操作可参考协议RFC95 ...

  9. Centos下nginx支持https协议

    1.首先配置nginx及其他插件,这个Google下,很多配置方案. 2.配置服务器的证书.操作步骤如下: [root@localhost ~]# cd /etc/pki/tls/certs [roo ...

  10. fbx模型

    [fbx模型] 1.FBX是Autodesk的一个用于跨平台的免费三维数据交换的格式(最早不是由Autodesk开发,但后来被其收购),目前被 众多的标准建模软件所支持,在游戏开发领域也常用来作为各种 ...