博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode Rotate List简单易懂解法
阅读量:4186 次
发布时间:2019-05-26

本文共 846 字,大约阅读时间需要 2 分钟。

/***************************************************

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

For example:

Given 1->2->3->4->5->NULL and k = 2,
return 4->5->1->2->3->NULL.
*******************************************************/

ListNode *rotateRight(ListNode *head, int k) {        if (head==NULL || k<=0){            return head;        }        //find the length of List        int len=1;        ListNode *p=head;        while( p->next != NULL ){            p = p->next;            len++;        }        //connect the tail to head        p->next = head;        //find the left place (take care the case - k > len)        k = len - k % len;        //find the place        for(int i=0; i
next; } //break the list head = p->next; p->next = NULL; return head; }

转载地址:http://hpdoi.baihongyu.com/

你可能感兴趣的文章
git命令缩写配置
查看>>
makefile常见问题
查看>>
ncverilog编译时Unrecognized system task or function: $fsdbDumpfile问题的解决方法
查看>>
window10配置环境不起作用
查看>>
在官网下载maven历史版本
查看>>
tomcat之启动类BootStrap
查看>>
tomcat处理请求的流程
查看>>
Spring之lazy-init
查看>>
类的加载机制
查看>>
SpringIoc
查看>>
spring bean 的生命周期
查看>>
常用的排序算法
查看>>
浅谈web授权常用策略随机
查看>>
jenkins自动部署随记
查看>>
Shell命令的随记
查看>>
TCP,HTTP,WEBSOCKET随记
查看>>
关于JVM内存区域的组成以及堆内存的回收原理
查看>>
JVM的垃圾回收机制以及回收策略随记
查看>>
生成XML的方法
查看>>
Reactor模式
查看>>