Rotate List || LeetCode
/**
* 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的更多相关文章
- 48. Rotate Image - LeetCode
Question 48. Rotate Image Solution 把这个二维数组(矩阵)看成一个一个环,循环每个环,循环每条边,每个边上的点进行旋转 public void rotate(int[ ...
- Rotate Image [LeetCode]
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- Rotate List —— LeetCode
Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...
- 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 ...
- Rotate Image leetcode java
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- Rotate List leetcode java
题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Gi ...
- 189. Rotate Array - LeetCode
Question 189. Rotate Array Solution 题目大意:数组中最后一个元素移到第一个,称动k次 思路:用笨方法,再复制一个数组 Java实现: public void rot ...
- 796. Rotate String - LeetCode
Question 796. Rotate String Solution 题目大意:两个字符串匹配 思路:Brute Force Java实现: public boolean rotateString ...
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
随机推荐
- BZOJ4379 : [POI2015]Modernizacja autostrady
两遍树形DP求出每个点开始往上往下走的前3长路以及每个点上下部分的直径. 枚举每条边断开,设两边直径分别为$A,B$,则: 对于第一问,连接两边直径的中点可得直径为$\max(A,B,\lfloor\ ...
- ACM Registration system
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- 【BZOJ】1110: [POI2007]砝码Odw
题意 给定\(n\)个砝码和\(m(1 \le n, m \le 100000)\)个背包\((1 \le n_i, m_i \le 1000000000)\),保证对于任意两个砝码都有一个是另一个的 ...
- js,html,css注释大集合
1.js注释: 单行注释,在注释内容前加符号 “//” <script type="text/javascript"> document.write("单行注 ...
- 【POJ2104/2761】K-th Number
Description You are working for Macrohard company in data structures department. After failing your ...
- Springmvc+Hibernate在Eclipse启动Tomcat需要很长时间的解决方法
最近在学习SpringMvc开发,有一个提问困扰了很久,就是在Eclipse启动Tomcat需要很长时间,大概要1分多钟. 启动日志: 九月 08, 2016 8:59:01 下午 org.apach ...
- hadoop CLASSNAME命令使用注意点
Hadoop中可是使用hadoop CLASSNAME命令.这个CLASSNAME就是你写好的类名.hadoop CLASSNAME命令类似于java classname. 使用hadoop CLAS ...
- nginx 中 PHP 调用PEAR.php遇到的问题
公司有个老项目,写了很多年了,是在apache 上面跑的,无意间,我想让它跑到nginx上,结果遇到了PEAR.php的问题,先安装pear 基本安富有就是 wget http://pear.php. ...
- js获取屏幕大小
1.js获取屏幕大小 <html> <script> function a(){ document.write( "屏幕分辨率为:"+screen.widt ...
- 使用C#实现FTP的文件上传和下载【转】
参考博文:http://blog.163.com/mity_rui@126/blog/static/1098136182013101525615577/