leetcode Rotate Array
来源:互联网 发布:网络神兽 编辑:程序博客网 时间:2024/06/04 19:48
原题链接: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].
class Solution {public: void Reverse(vector<int>& nums, int i, int j) { for(; i < j; i++, j--) { int ret = nums[i]; nums[i] = nums[j]; nums[j] = ret; } } void rotate(vector<int>& nums, int k) { size_t n = nums.size(); if (!n || !(k % n)) return; k %= n; Reverse(nums, 0, n - k -1); Reverse(nums, n - k, n - 1); Reverse(nums, 0, n - 1); }};
0 0
- [leetcode][array] Rotate Array
- LeetCode[Array]: Rotate Image
- LeetCode:Rotate Array
- [LeetCode] Rotate Array
- *LeetCode-Rotate Array
- [LeetCode]189.Rotate Array
- Rotate Array - LeetCode - Java
- Rotate Array--Leetcode(Java)
- Leetcode--Rotate Array
- LeetCode: Rotate Array
- LeetCode Rotate Array
- Rotate Array(leetcode)
- leetcode Rotate Array
- Leetcode: Rotate Array
- [Leetcode]11 Rotate Array
- [LeetCode][189][Rotate Array]
- Leetcode:Rotate Array
- LeetCode: Rotate Array
- LeetCode P144 Binary Tree Preorder Traversal
- visual studio开启多核编译方法
- Error:ERROR ITMS-90474: "Invalid Bundle. iPad Multitasking support requires these orientations:
- 1059: [ZJOI2007]矩阵游戏
- 一篇介绍NStimer深层原理的文章
- leetcode Rotate Array
- JAVA基础——新概念理解
- ogg initial load初始化加载
- PHP 连接 oracle数据库(可远程)的测试操作
- JavaScript中的类与对象
- 简单面试题知识点复习 (部分)
- Django 基础教程
- leetcode Excel Sheet Column Number
- hibernate cascade属性 all-delete-orphan