189. Rotate Array
problem
189. Rotate Array
solution1: 暴力破解法(Time Limit Exceeded)
class Solution { public:void rotate(vector<int>& nums, int k) {int tmp, pre;for(int i=0; i<k; i++){pre = nums[nums.size()-1];for(int j=0; j<nums.size(); j++){tmp = nums[j];nums[j] = pre;pre = tmp;}}} };
View Code
solution2: 空间换取时间
class Solution { public:void rotate(vector<int>& nums, int k) {vector<int> tmp(nums.size(), 0);for(int i=0; i<nums.size(); i++){tmp[(i+k)%nums.size()] = nums[i];}for(int i=0; i<nums.size(); i++){nums[i] = tmp[i];}} };
1. Leetcode_Rotate Array;
转载于:https://www.cnblogs.com/happyamyhope/p/10088859.html
189. Rotate Array相关推荐
- [勇者闯LeetCode] 189. Rotate Array
[勇者闯LeetCode] 189. Rotate Array Description Rotate an array of n elements to the right by k steps. F ...
- Leet Code OJ 189. Rotate Array [Difficulty: Easy]
题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the ar ...
- LeetCode 189. Rotate Array
题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the ar ...
- leetcode python3 简单题189. Rotate Array
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百八十九题 (1)题目 英文: Given an array, rotate t ...
- (数组) leetcode 189. Rotate Array
注意:k可能比数组的长度大,所 k = k%n (n为数组长度). 思路一:暴力法.循环移动k次. class Solution { public:void rotate(vector<int& ...
- leetcode-189. Rotate Array
189. Rotate Array Rotate an array of n elements to the right by k steps. For example, with n = 7 and ...
- 9.leetcode题目189: Rotate Array
这道题一直做不好.. Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, ...
- LeetCode Rotate Array(数组的旋转)
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- 【LeetCode从零单排】No189 .Rotate Array
题目 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the arr ...
- HappyLeetcode50:Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
最新文章
- 自动驾驶多相机与多雷达数据融合方法汇总
- 新功能:阿里云负载均衡SLB支持HTTPS虚拟主机功能(SNI)
- 百度坐标转换火星坐标UDF
- spring boot 日志文件配置(logback-spring.xml)亲测可用!
- json数据交换的例了
- 云教版认识计算机说课,【教学设计】第1册第1课《认识电脑交朋友》
- TortoiseGit 本地仓库和远程仓库建立联系_入门试炼_02
- OK6410开发板学习之外部中断(按键点亮led和蜂鸣器)
- 使用LazZiya.ExpressLocalization开发多区域性ASP.NET Core 3、2、1项目
- linux 平台安装ionic开发调试编译环境(Android)
- xen服务器不能挂载iso文件,Citrix XenCenter安装VM:挂载ISO详解
- MATLAB music分解信号,MUSIC算法信号频率问题求解
- 二阶、三角、三阶、四阶、五阶魔方还原方法总结
- python之abc和six
- 300ETF期权适合进行短线交易吗?
- Realtek WiFi concurrent 模式介绍
- 开机脚本之——鼠标滚轮调整音量
- 工程建设项目业务学习
- 跨境电商供应链系统:轻松统筹管理进出口跨境电商系统
- tomcat修改404页面
热门文章
- java窗口全屏_java如何改全屏为窗口?求啊啊啊啊
- linux系统securecrt无法访问,在securecrt官网下载的securecrt for linux版无法启动
- 施乐7556_富士施乐Fuji Xerox WorkCentre 7556 驱动
- 潜在语义索引(Latent Semantic Indexing, LSI)——快速教程
- The Closest M Points//kd树+优先队列
- 20172318 2017-2018-2 《程序设计与数据结构》第11周学习总结
- SpringMVC拦截器(包括自定以拦截器--实现HandlerInterceptorAdapter)(资源和权限管理)...
- Dos window下运行java程序
- 给model模型传数组参数
- Python [6] IT资产管理(下)