思路

先把list变成一个环,然后转到指定位置
注意有个取模的处理

code


func rotateRight(head *ListNode, k int) *ListNode {if head == nil || head.Next == nil || k == 0 {return head}len := 1tail := headfor tail.Next != nil {tail = tail.Nextlen++}tail.Next = head //变成一个环k = k % len      //因为是个环,所以不用转超过一圈for i := 0; i < len-k; i++ {tail = tail.Next}head = tail.Nexttail.Next = nilreturn head
}

更多内容请移步我的repo:https://github.com/anakin/golang-leetcode

Leetcode Golang 61. Rotate List.go相关推荐

  1. leetcode 61 Rotate List ----- java

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

  2. LeetCode 61. Rotate List

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Gi ...

  3. leetcode 61. Rotate List

    Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 定义两个指 ...

  4. 61. Rotate List

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Gi ...

  5. 【LeetCode】48. Rotate Image (2 solutions)

    Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...

  6. LeetCode Golang 9.回文数

    9. 回文数 第一种办法 :itoa 转换为字符串进行处理: package mainimport ("strconv""fmt" )//判断一个整数是否是回文 ...

  7. Leetcode Golang 77. Combinations.go

    思路 看到这个词,马上就想到了回溯 code func combine(n int, k int) [][]int {var res [][]inthelper(&res, []int{}, ...

  8. 【LeetCode】61.旋转链表

    给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: 1->2->3->4->5->NULL, k = 2 输出: 4-& ...

  9. 【Golang Leetcode】总目录(Day1~100)

    Leetcode Golang Day1~10 Golang每日一练(leetDay0001) 1. 两数之和 Two Sum 2. 两数相加 Add Two Numbers 3. 无重复字符的最长子 ...

最新文章

  1. 360浏览器5兼容模式吗_Vue-cli项目,打包生产模式,部分用户360浏览器极速模式下奔溃...
  2. hdu2100 26进制加法
  3. Opencv判断是否加载图片的两种方法
  4. 最长连续序列Python解法
  5. 提取地图中道路_非机器学习方法·从遥感影像中提取道路
  6. # javascript 总结
  7. 英特尔固态硬盘540s开卡_英特尔Z490主板绝配?技嘉PCIe 3.0 x8固态硬盘测试:6.5GB/s读速...
  8. find_first_of和find函数的区别
  9. 第一章:Python的基本数据类型-第二节:Python中表示“有序”(序列)的数据类型
  10. boost.asio异步并发Tcp服务器
  11. 【LeetCode】Combination Sum(组合总和)
  12. 【转】修改UCGUI源代码以支持多个独立窗体的说明
  13. 富文本编辑器粘贴图片
  14. 游程编码run length code
  15. PHP 获取微视无水印源地址_最新抖音短视频无水印地址解析原理(抖音免费解析接口),以PHP代码为例...
  16. 一阶微分方程解的存在定理
  17. Flask HTML模板引擎详解
  18. 【PHP】如何提高网页加载速度?
  19. RFSOC 6U VPX标准板卡
  20. 基础乐理 - 反复记号

热门文章

  1. ChatGPT研究分享:机器第一次开始理解人类世界
  2. 【SpringCloud学习06】RabbitMQ
  3. CCRC信息安全服务资质证书如何查询
  4. 语音识别工具箱之kaldi介绍
  5. iOS高级分享 — 谈谈 IOS 13
  6. 小米游戏四种登录方式与两种登录方式的问题
  7. vue数组循环遍历中途跳出整个循环
  8. 电磁场仿真——均匀平面波在真空中的三维传播情况的仿真
  9. vasp-phonopy编译
  10. 利用CRM系统分析客户数据