/**
* 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. iOS之05-三大特性之封装

    本次主要学习面向对象的三大特性:封装.继承和多态中的封装 封装 1. 好处 降低耦合率 可重复调用类中的属性 提高安全性,外部不能随便修改变量的值,保证了数据的安全性 2. set方法 1.作用:提供 ...

  2. Leap Motion发布新平台,直击下一代移动端VR/AR手部追踪

    2013年,动作捕捉技术公司Leap Motion发布了面向PC的体感控制器,不过销量并不乐观.随着2014年虚拟现实技术的再一次兴起,它发布一款用于Oculus Rift的附加设备,从而正式登上VR ...

  3. Android 魅族等SmartBar适配

    通过反射获取是否含有SmartBar: /** * 判断是否有SmartBar */ private boolean hasSmartBar() { // SP存储是否显示SmartBar if (! ...

  4. 【POJ】2096 Collecting Bugs

    http://poj.org/problem?id=2096 题意:s个系统n种bug,每天找出一个bug,种类的概率是1/n,系统的概率是1/s.问:每个系统至少找出一个bug:每种类的bug都被找 ...

  5. Oracle connect by 树查询之二

    先用scott用户下的emp表做实验.emp表有个字段,一个是empno(员工编号),另一个是mgr(上级经理编号)下面是表中所有数据 1 select * from emp start with e ...

  6. 如何使用Apache的ab工具进行网站性能测试

    1.打开Apache服务器的安装路径,在bin目录中有一个ab.exe的可执行程序,就是我们要介绍的压力测试工具. 2.在Windows系统的命令行下,进入ab.exe程序所在目录,执行ab.exe程 ...

  7. 【Go语言】LiteIDE使用的个人使用方法

    Go语言开发 可以使用的IDE很多 (Goclipse,sublime,notepad++,vim等)目前使用的最顺手的就是LiteIDE了 但是尽管这样,一开始使用LiteIDE也有很多不习惯的地方 ...

  8. [LintCode] Remove Linked List Elements 移除链表元素

    Remove all elements from a linked list of integers that have value val. Have you met this question i ...

  9. thinkphp框架3.2的cookie删除问题记录

    在使用框架删除cookie时,发现cookie(null)不起作用.后来查看官网相关信息,看到了讨论http://www.thinkphp.cn/bug/2602.html

  10. IE10以下的IE浏览器在form表单提交、a标签等场景下,接收application/json类型的响应时,会提示是否要下载该json文件

    IE10以下的IE浏览器并不支持application/json这种response格式,所以需要在服务端先将对象转成json字符串然后,设置Content-Type为text/html的类型,再返回 ...