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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

189. Rotate Array

2019-11-14 12:44:50
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 江油市| 琼海市| 庄河市| 广宁县| 博白县| 长顺县| 赣榆县| 涪陵区| 巴塘县| 新和县| 石家庄市| 岑溪市| 天峻县| 横山县| 吴堡县| 高青县| 怀柔区| 重庆市| 江津市| 西乌| 遂溪县| 饶河县| 太白县| 固阳县| 金湖县| 淮南市| 贵溪市| 德兴市| 永城市| 松阳县| 新昌县| 汉川市| 文成县| 鄄城县| 钟祥市| 新绛县| 永新县| 黄石市| 明星| 偏关县| 涞源县|