博客
关于我
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/

你可能感兴趣的文章
NewspaceGPT的故事续写能力太强了
查看>>
NewspaceGPT绘制时序图
查看>>
NewspaceGPT绘制类图
查看>>
new一个对象的过程
查看>>
new和delete用法小结
查看>>
new对象时,JVM内部究竟藏了什么小秘密?
查看>>
new操作符的实现原理
查看>>
Next.js React Server Components 教程
查看>>
NextGen Mirth Connect XStream反序列化远程代码执行漏洞(CVE-2023-43208)
查看>>
next项目部署到服务器pm2进程守护
查看>>
nexus 介绍
查看>>
nexus上传jar
查看>>
Nexus指南中的更新强调集成和透明度的重要性
查看>>
Nexus指南已经发布
查看>>
Nexus(1):Nexus的安装与配置
查看>>
NFC技术:概述
查看>>
NFinal学习笔记 02—NFinalBuild
查看>>
NFS
查看>>
nfs mount 故障 mount.nfs: access denied by server while mounting 10.0.100.208:/backup_usb
查看>>
NFS Server及Client配置与挂载详解
查看>>