博客
关于我
leetcode 61旋转链表 java双100
阅读量:138 次
发布时间:2019-02-27

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

class Solution {       public ListNode rotateRight(ListNode head, int k) {           if(head==null || k==0) {               return head;        }        ListNode cur = head;//假节点指头        ListNode tail = null;//尾        int length = 1;        while(cur.next != null) {               cur = cur.next;            length++;        }//求长度        int num = length-(k%length);        tail = cur;//指尾        cur.next = head;//改循环链表        cur = head;        for(int i=0;i

本题说是循环旋转,但其实是将尾部向前数第K个元素作为头,原来的头接到原来的尾上,这应该也是一种更好的思路java双100

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

你可能感兴趣的文章
nodejs Error: request entity too large解决方案
查看>>
Nodejs express 获取url参数,post参数的三种方式
查看>>
nodejs http小爬虫
查看>>
nodejs libararies
查看>>
vue3+element-plus 项目中 el-switch 刷新后自动触发change?坑就藏在这里!
查看>>
nodejs npm常用命令
查看>>
nodejs npm常用命令
查看>>
Nodejs process.nextTick() 使用详解
查看>>