leetcode--189.Rotate
来源:互联网 发布:雷锋的故事 知乎 编辑:程序博客网 时间:2024/06/03 14:29
L189:
将一个数组里的数,向右移动 k位。(shift)。要求多种方法。
坑:k可能大于len,所以需要取余。
方案1:
将数组复制,依次填入新的位置。新的位置为(i+k)%n
方案2:
将数组reverse。
将数组第0-k-1位reverse
将数租第k-len-1位reverse
方案3:
循环,先为某个数找到新位置,再为新位置上原来的数找到它的新位置。如此循环。
倘若下标回到start,而移动的位数小于len,则将start+1,继续进行
阅读全文
0 0
- [LeetCode]189.Rotate Array
- [Leetcode] 189.Rotate Array
- LeetCode 189. Rotate Array
- 【LeetCode】189.Rotate Array
- [leetcode] 189.Rotate Array
- 【leetcode】189. Rotate Array
- Leetcode 189. Rotate Array
- 189. Rotate Array LeetCode
- [LeetCode]189. Rotate Array
- leetcode-189.-Rotate Array
- LeetCode 189. Rotate Array
- leetcode 189. Rotate Array
- LeetCode *** 189. Rotate Array
- [LeetCode]189. Rotate Array
- LeetCode 189. Rotate Array
- leetcode-189. Rotate Array
- Leetcode 189. Rotate Array
- leetcode 189. Rotate Array
- SocketDemo 类似聊天室
- C语言程序,求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字,例如:2+22+222+2222+22222
- 动态规划-343. Integer Break
- Spring系列之Spring常用注解总结
- 使用Loader获取Android联系人列表
- leetcode--189.Rotate
- ndk c调java
- stl set讲解
- u启动盘制作
- 成对使用new和delete时要采取相同形式
- leetcode--169.Major Element
- ConcurrentHashMap分析
- 总结 Date 2017.09.23
- java开发C语言编译器:消除冗余语句和把ifelse控制语句编译成字节码