/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* rotateRight(struct ListNode* head, int k) {
struct ListNode *sentry,*p,*temp,*tail;
int len=,index; if(head==NULL)return NULL;
sentry=(struct ListNode *)malloc(sizeof(struct ListNode));
sentry->next=NULL;
p=head;
tail=sentry;
while(){
temp=(struct ListNode*)malloc(sizeof(struct ListNode));
temp->val=p->val;
temp->next=NULL;
tail->next=temp;
tail=temp;
len++;
if(p->next==NULL)break;
p=p->next;
}
p->next=sentry->next;
k=k%len,index=;
p=head;
while(p){
if(index==(len-k)){
temp=p;
}
if(index==(*len-k-)){
p->next=NULL;
break;
}
index++;
p=p->next;
}
return temp;
}

Rotate List || LeetCode的更多相关文章

  1. 48. Rotate Image - LeetCode

    Question 48. Rotate Image Solution 把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转 public void rotate(int[ ...

  2. Rotate Image [LeetCode]

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  3. Rotate List —— LeetCode

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...

  4. Rotate Array leetcode

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  5. Rotate Image leetcode java

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  6. Rotate List leetcode java

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Gi ...

  7. 189. Rotate Array - LeetCode

    Question 189. Rotate Array Solution 题目大意:数组中最后一个元素移到第一个,称动k次 思路:用笨方法,再复制一个数组 Java实现: public void rot ...

  8. 796. Rotate String - LeetCode

    Question 796. Rotate String Solution 题目大意:两个字符串匹配 思路:Brute Force Java实现: public boolean rotateString ...

  9. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

随机推荐

  1. Thread 的使用

    对于Thread 的使用,我要注意的是我经常忽略".start()".之前由于在android开发中,如果是使用网络加载的功能,这个部分需要新增线程,不能在主线程使用. 然后注意要 ...

  2. Post请求

    写在前面的话: XMLHttpRequest对象的open方法的第一个参数为request-type,取值可以为get或post.本篇介绍post请求. 使用post方式时,浏览器会把各表单中字段元素 ...

  3. [R]R下as.Date()函数的坑

    问题描述: 在本地使用as.Date()函数从POSIXct类型中提取date时,出现了日期不一致的错误.导致处理数据时,总是出问题. 还好被领导发现数据有误,不然这个bug不知道还要潜伏多久.尽管如 ...

  4. Linux 启动项介绍

    1. init进程 非内核进程中第一个被启动运行的,因此它的进程编号PID的值总是1.init读它的配置文件/etc/inittab,决定需要启动的运行级别(Runlevel,分别由0到6的整数表示) ...

  5. Activiti工作流引擎参考资料

    Activiti工作流引擎使用 工作流-Activiti核心API介绍 传智播客Activiti工作流视频教程(企业开发实例讲解) 工作流引擎Activiti演示项目 http://www.kafei ...

  6. HDU 1452 (约数和+乘法逆元)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1452 题目大意:求2004^X所有约数和,结果mod 29. 解题思路: ①整数唯一分解定理: 一个 ...

  7. NOIP欢乐模拟赛 T3 解题报告

    3.小澳的葫芦 (calabash.cpp/c/pas) [题目描述] 小澳最喜欢的歌曲就是<葫芦娃>. 一日表演唱歌,他尽了洪荒之力,唱响心中圣歌. 随之,小澳进入了葫芦世界. 葫芦世界 ...

  8. 【noiOJ】p8209

    06:月度开销 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 农夫约翰是一个精明的会计师.他意识到自己可能没有足够的钱来维持农场的运转了.他计算出并记录下了 ...

  9. poj 1995 裸快速幂

    1. poj 1995  Raising Modulo Numbers 2.链接:http://poj.org/problem?id=1995 3.总结:今天七夕,来发水题纪念一下...入ACM这个坑 ...

  10. VS2010 C++环境下DLL和LIB文件目录及名称修改

    VS2010 C++环境下DLL和LIB文件目录及名称修改 转自:http://blog.csdn.net/archielau/article/details/8507581 DLL工程,Debug版 ...