当前位置:网站首页>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)
边栏推荐
- Supervisor monitors gearman tasks
- webcodecs
- 聊聊支付流程的设计与实现逻辑
- 基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
- Closure and closure function
- 2022-2028 global marking ink industry research and trend analysis report
- Three gradient descent methods and code implementation
- 模块九作业
- [Tongxin UOS] scanner device management driver installation
- (9) Opencv Canny edge detection
猜你喜欢

Computer graduation project PHP library book borrowing management system

Redis core technology and practice - learning notes (11): why not just string

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

Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals

An academic paper sharing and approval system based on PHP for computer graduation design

Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up

How do microservices aggregate API documents? This wave of operation is too good

2022-2028 global aircraft head up display (HUD) industry research and trend analysis report

Prototype inheritance..

Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
随机推荐
Sensor 调试流程
Sensor debugging process
Graduation summary
2022-2028 global scar care product industry research and trend analysis report
BFS - topology sort
Kotlin's collaboration: Context
SQL injection -day16
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
[combinatorics] generating function (use generating function to solve the combination number of multiple sets R)
Computer graduation design PHP campus address book telephone number inquiry system
OpenSSL的SSL/BIO_get_fd
PHP MySQL reads data
一入“远程”终不悔,几人欢喜几人愁。| 社区征文
2022-2028 global marking ink industry research and trend analysis report
AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
Have you learned the correct expression posture of programmers on Valentine's day?
webcodecs
2022-2028 global petroleum pipe joint industry research and trend analysis report
2022-2028 global physiotherapy clinic industry research and trend analysis report
How to expand the capacity of golang slice slice