代码:

 #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. Linux LED字符设备驱动

    // 申请IO资源 int gpio_request(unsigned gpio, const char *label); // 释放IO资源 void gpio_free(unsigned gpio ...

  2. 有限状态机(Finite-state machine, FSM)的C语言实现

    有限状态机,也称为FSM(Finite State Machine),其在任意时刻都处于有限状态集合中的某一状态.当其获得一个输入字符时,将从当前状态转换到另一个状态,或者仍然保持在当前状态.任何一个 ...

  3. Ajax验证用户名

    用Ajax验证用户名: 接口: get guestbook/index.php m : index a : verifyUserName username : 要验证的用户名 返回 { code : ...

  4. POJ2478(欧拉函数)

    Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15242   Accepted: 6054 D ...

  5. ssh-copy-id:/usr/bin/ssh-copy-id: ERROR: No identities found

    $ ssh-copy-id remote-machine 公钥,私钥已经生成,执行上述命令完毕出现如下错误: /usr/bin/ssh-copy-id: ERROR: No identities fo ...

  6. Linux: How to delete a disk or LUN reference from /dev

    In AIX, there is rmdev command to remove a disk/LUN from /dev directory i.e to make the disk/LUN una ...

  7. mysql事务之二:MySQL隔离级别演示

    登录mysql: mysql -u root -p123456 Mysql 版本号 mysql> select version(); +-------------------------+ | ...

  8. 1078 Hashing

    题意:给出表长和待插入的元素,求每个元素的插入位置,散列函数为H(key)=key%TSize,解决冲突利用平方探测法(只考虑正向偏移). 思路:同1145 Hashing - Average Sea ...

  9. pandas索引操作

    Pandas的索引操作 索引对象Index 1. Series和DataFrame中的索引都是Index对象 示例代码: print(type(ser_obj.index)) print(type(d ...

  10. RAD 10 蓝牙

    http://docwiki.embarcadero.com/Libraries/Seattle/en/System.Bluetooth.TBluetoothLEManager.StartDiscov ...