1 Star 0 Fork 0

星缘 / arithmetic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo.go 478 Bytes
一键复制 编辑 原始数据 按行查看 历史
星缘 提交于 2022-02-23 11:56 . 排序算法
package main
import (
"fmt"
)
func rotate(nums []int, k int) {
if k <= 0 {
fmt.Println(nums)
return
}
l := len(nums) // 5
if k > l{
k = k%l
}
ca := []int{}
for i := 0; i < k; i++ {
ca = append(ca, nums[l-i-1])
}
// 2
for a := l - k; a > 0; a-- {
// fmt.Println(a)
nums[a+k-1] = nums[a-1]
}
for key,value := range ca{
nums[k-key-1] = value
}
fmt.Println(nums)
}
func main() {
fmt.Println(3%2)
n := []int{1, 2, 3, 4, 5}
k := 3
rotate(n, k)
}
Go
1
https://gitee.com/yun-ink/arithmetic.git
git@gitee.com:yun-ink/arithmetic.git
yun-ink
arithmetic
arithmetic
master

搜索帮助