国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

189. Rotate Array

2019-11-14 11:52:07
字體:
供稿:網(wǎng)友

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.

編程珠璣里面也有類似這種思路的例子

class Solution {public: void rotate(vector<int>& nums, int k) { int n = nums.size(); reverse(nums.begin(), nums.begin() + n - k % n); reverse(nums.begin() + n - k % n, nums.begin() + n); reverse(nums.begin(), nums.end()); }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 合阳县| 金门县| 饶阳县| 五常市| 景宁| 泽普县| 武宁县| 江阴市| 天津市| 洛川县| 新巴尔虎右旗| 海淀区| 延川县| 肇源县| 施甸县| 安达市| 新化县| 若羌县| 林西县| 宁都县| 菏泽市| 遂宁市| 斗六市| 额济纳旗| 虞城县| 淮南市| 石台县| 许昌县| 界首市| 兴海县| 重庆市| 汝阳县| 石阡县| 双牌县| 积石山| 珲春市| 高淳县| 宁陵县| 沐川县| 德州市| 霍山县|