当前位置:网站首页>Array rotate array
Array rotate array
2022-06-10 22:11:00 【Morris_】
LC Rotated array
Ideas : Move last element to first , Elements in other positions move back one bit , loop k Time
- Swift
/* example : nums = [1,2,3], k = 4 [3,1,2] [2,3,1] [1,2,3] [3,1,2] Each time the last element is moved to the first place , Other bit elements move backward one bit in turn ; Cyclic movement k Time */
func rotate(_ nums: inout [Int], _ k: Int) {
var k: Int = k
while k > 0 {
let temp: Int = nums.last!
var index = nums.count - 1
while index > 0 {
nums[index] = nums[index - 1]
index -= 1
}
nums[0] = temp
k -= 1
}
}
边栏推荐
- Mysql之將查詢結果插入到其它錶中
- Course design of imitation pottery ticket of wechat applet
- . Net open source free lunch is over?
- NFT copyright / royalties
- Shell implements SSH login and executes commands
- C中字符串查找
- Qingniao Changping campus of Peking University: can I learn UI with a high school degree?
- Abbexa 8-OHdG CLIA kit solution
- 在Oracle表中进行关键词搜索的过程
- NFT版权/版税
猜你喜欢

C language ---5 initial string, escape character and comment

在模仿学习中进步的智能机器人

Abbexa cdan1 siRNA instruction manual

C#使用S7.net连接西门子S1200PLC,C#直接连接西门子PLC

NFT copyright / royalties

磁盘序列号,磁盘ID,卷序列号的区别

NFT版权/版税

【MySQL】常见数据类型总结

Notes to entry: do I need to know programming for O & M?

Naturalspeech model synthetic speech achieves human speech level for the first time in CMOS test
随机推荐
Mysql的回表查询?如何避免?
oc swift 混编
[nk] 牛客月赛51 F-平均题
Are you still writing the TS type code
php伪协议实现命令执行详情
变量(自动变量、静态变量、寄存器变量、外部变量)与C的内存分配malloc/free、calloc/recalloc
I'm doing something cool
自制Table錶格
Tableau auto - fabriqué
Mysql之將查詢結果插入到其它錶中
磁盘序列号,磁盘ID,卷序列号的区别
一次SQL查询优化原理分析(900W+数据从17s到300ms)
Which city should I go to after I graduate from it? Which position has a high salary? Which companies have good treatment?
php的exec函数
C language -- 3 variables for beginners
构建幼儿Steam教育实施策略
protoc protoc-gen-go protobuf 之间的关系
Self made table
[nk] Niuke monthly competition 51 f-average question
[generation confrontation network learning part I] classic Gan and its existing problems and related improvements