当前位置:网站首页>189. Rotation array
189. Rotation array
2022-07-03 18:19:00 【The_ Dan】
class Solution {
public:
void rotate(vector<int>& nums, int k) {
int n = nums.size();
k = k % n;
reverse(nums, 0, n - 1);
reverse(nums, 0, k - 1);
reverse(nums, k, n - 1);
}
void reverse(vector<int>& nums, int begin, int end){
while(begin < end){
swap(nums[begin], nums[end]);
begin++;
end--;
}
}
};
Accepted
38/38 cases passed (36 ms)
Your runtime beats 7.9 % of cpp submissions
Your memory usage beats 98.48 % of cpp submissions (24.2 MB)
边栏推荐
- Self executing function
- 企业级自定义表单引擎解决方案(十二)--表单规则引擎2
- [LINUX]CentOS 7 安装MYSQL时报错“No package mysql-server available“No package zabbix-server-mysql availabl
- The vscode code is automatically modified to a compliance code when it is formatted and saved
- Talk about the design and implementation logic of payment process
- Unsafe类的使用
- Have you learned the correct expression posture of programmers on Valentine's day?
- PHP MySQL where clause
- Keepalived setting does not preempt resources
- How to install PHP on Ubuntu 20.04
猜你喜欢
Computer graduation design PHP campus address book telephone number inquiry system
Sensor debugging process
2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
English语法_形容词/副词3级 - 倍数表达
Summary and Reflection on the third week of winter vacation
List的stream中Long对象与long判等问题记录
Computer graduation design PHP makeup sales Beauty shopping mall
Computer graduation design PHP sports goods online sales system website
Five problems of database operation in commodity supermarket system
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
随机推荐
G1 garbage collector of garbage collector
win32:堆破壞的dump文件分析
[combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
This diversion
English語法_名詞 - 分類
Codeforces Round #803 (Div. 2) C. 3SUM Closure
Talk about the design and implementation logic of payment process
(9) Opencv Canny edge detection
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
Change the single node of Postgres database into master-slave
Count the number of pixel values in the image
PHP MySQL order by keyword
Use of unsafe class
Valentine's day, send you a little red flower~
How do microservices aggregate API documents? This wave of operation is too good
What London Silver Trading software supports multiple languages
[combinatorics] generating function (commutative property | derivative property | integral property)
SQL injection -day16
MySQL grouping query
[combinatorics] generating function (example of using generating function to solve the number of solutions of indefinite equation)