代码:

 #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. The method of type must override a superclass method解决方式(转)

    今天做struts2上传文件的时候出现了这个问题: The method execute() of type UploadAction must override or implement a sup ...

  2. ReactJS开发环境搭建与相关工具介绍

    现在Web开发的技术几年前相比可谓变化之大.各种各样的框架,各种各样的工具,让Web开发效率更高,开发出来的效果更好.同时带来的是开发环境的复杂度相比以前是成倍的增加.ReatJS框架是现在比较流行的 ...

  3. js练习题笔记

    javascrip测试题: 一.选择题(每题2分,多选题错选.少选不得分) 1.分析下段代码输出结果是( )    var arr = [2,3,4,5,6];    var sum =0;    f ...

  4. $GLOBALS超级全局变量(PHP学习)

    1.$GLOBALS是一个数组,里面有所有的全局变量 2.$GLOBALS是超级全局变量,函数内部可以通过它直接操作全局变量.(严重不推荐,因为违反了封装原则) 3.通过$GLOBALS操作全局变量, ...

  5. UBUNTU readelf的安装

    大多数情况下,linux环境上默认可能都装有readelf,但是也有少数情况可能没有装,我自己用的ubuntu的linux虚拟机就没有装readelf.readelf本身是一个分析elf很好用的工具. ...

  6. PhantomJS 一个隐形的浏览器

    下载地址: http://phantomjs.org/download.html 使用方法: 下载压缩包解压出来找到phantomjs.exe 放到python的根目录下

  7. 2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)

    Deleting Edges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. Java-Maven-Runoob:Maven教程

    ylbtech-Java-Maven-Runoob:Maven教程 1.返回顶部 1. Maven 教程 Maven 翻译为"专家"."内行",是 Apache ...

  9. JeeSite基础知识(一)

  10. gevent异步,io自动切换

    #!/usr/bin/env python # encoding: utf-8  # Date: 2018/6/19 # # from gevent import monkey  # 这俩行必须放在首 ...