Leetcode_189 Rotate Array
来源:互联网 发布:淘宝哪家卖苹果手机好 编辑:程序博客网 时间:2024/06/12 00:05
原题地址:https://leetcode.com/problems/rotate-array/#/description
题目:
Rotate an array of n elements to the right by k steps.
For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7]
is rotated to [5,6,7,1,2,3,4]
.
Note:
Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
[show hint]
Related problem: Reverse Words in a String II
这是一道简单题目,写两个解法。两个解法的时间复杂度均为o(n),第一种解法的空间复杂度为o(1),第二种解法的空间复杂度为o(n)。
解法一:
解法二:
可见,第一种时间上效率稍微好点,空间占用也比较少。第一种方法稍微好一些。
阅读全文
0 0
- Leetcode_189 Rotate Array
- Leetcode_189 Rotate Array
- leetcode_189. Rotate Array 原地旋转数组
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- rotate array
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- Rotate Array
- 第十三周 【项目3
- Android7.0相机图册图片剪切封装
- ios实现qq空间飘落的花瓣(swift—粒子发射器)
- 省份-城市-区/县 下拉选
- 【十八掌●武功篇】第八掌:HBase之Shell
- Leetcode_189 Rotate Array
- Centos7及以下版本防火墙的打开关闭和查看开放端口
- Oracle的连接详解(左连接、右连接、全连接...)
- 第十二周——项目一最短路径(3)Dijkstra算法的验证(从一个顶点到其余各顶点的最短路径)
- 支付宝的服务器端的开发流程
- 【第十一周】项目4
- fstream,sstream的学习记录(备忘)
- FPGA 学习笔记
- redis数据备份,迁移