当前位置:网站首页>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)
边栏推荐
- Enterprise custom form engine solution (12) -- form rule engine 2
- Class exercises
- How to install PHP on Ubuntu 20.04
- Introduction to PHP MySQL
- OpenSSL的SSL/BIO_get_fd
- English语法_形容词/副词3级 - 倍数表达
- Keepalived setting does not preempt resources
- Redis core technology and practice - learning notes (VII) sentinel mechanism
- Three gradient descent methods and code implementation
- Summary and Reflection on the third week of winter vacation
猜你喜欢

Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding
![[combinatorics] generating function (summation property)](/img/74/e6ef8ee69ed07d62df9f213c015f2c.jpg)
[combinatorics] generating function (summation property)

微服务组件Sentinel控制台调用

2022-2028 global physiotherapy clinic industry research and trend analysis report

How to track the real-time trend of Bank of London

How to install PHP on Ubuntu 20.04

English grammar_ Adjective / adverb Level 3 - multiple expression

As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
![Bloom filter [proposed by bloom in 1970; redis cache penetration solution]](/img/f9/27a75454b464d59b9b3465d25fe070.jpg)
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]

Talk about the design and implementation logic of payment process
随机推荐
解决Zabbix用snmp监控网络流量不准的问题
Remote office tools sharing | community essay solicitation
A. Berland Poker & 1000 [simple mathematical thinking]
SDNUOJ1015
[tutorial] build your first application on coreos
Module 9 operation
English语法_名词 - 分类
[combinatorics] generating function (property summary | important generating function)*
The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
Talk about the design and implementation logic of payment process
Fedora 21 安装 LAMP 主机服务器
How to deploy applications on kubernetes cluster
Solve the problem of inaccurate network traffic monitored by ZABBIX with SNMP
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
G1 garbage collector of garbage collector
AcWing 271. 杨老师的照相排列【多维DP】
Research on Swift
模块九作业
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation)
OpenSSL的SSL/BIO_get_fd