当前位置:网站首页>牛客网:旋转数组
牛客网:旋转数组
2022-06-25 11:10:00 【lsgoose】

这题是用数组翻转做的,是不是没想到...
挺神奇的,从题目的例子来看:
123456翻转整个变成654321
然后我们翻转前2位就变成564321,翻转后4位就变成了561234,是不是很神奇....
一开始我还想着用循环移位来做...
答案如下所示:
class Solution {
public:
/**
* 旋转数组
* @param n int整型 数组长度
* @param m int整型 右移距离
* @param a int整型vector 给定数组
* @return int整型vector
*/
vector<int> solve(int n, int m, vector<int>& a) {
m = m%n;
reverse(a.begin(), a.end());
reverse(a.begin(), a.begin()+m);
reverse(a.begin()+m, a.end());
return a;
}
};边栏推荐
- Jincang database kingbasees plug-in force_ view
- Network remote access using raspberry pie
- Handler、Message、Looper、MessageQueue
- Bayes
- SQL注入漏洞(绕过篇)
- Task03 probability theory
- Dragon Book tiger Book whale Book gnawing? Try the monkey book with Douban score of 9.5
- [maintain cluster case set] gaussdb query user space usage
- 10.1. Oracle constraint deferred, not deferred, initially deferred and initially deferred
- Spannable and editable, spannablestring and spannablestring
猜你喜欢

Netease's open source distributed storage system curve officially became the CNCF sandbox project

Jincang KFS data cascade scenario deployment

FPGA基于VGA显示字符及图片

基于Minifilter框架的双缓冲透明加解密驱动 课程论文+项目源码

SystemVerilog(十三)-枚举数据类型

龙书虎书鲸书啃不动?试试豆瓣评分9.5的猴书

基于C语言的图书信息管理系统 课程论文+代码及可执行exe文件

Use of three-level linkage plug-ins selected by provinces and cities

C disk uses 100% cleaning method

基於Minifilter框架的雙緩沖透明加解密驅動 課程論文+項目源碼
随机推荐
A difficult mathematical problem baffles two mathematicians
从GEE中免费获取全球人类住区层 (GHSL) 数据集
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-7
Jincang database kingbasees plug-in force_ view
Free access to the global human settlements layer (ghsl) dataset from Gee
Network remote access using raspberry pie
2022 PMP project management examination agile knowledge points (2)
relu与sigmod的比较
Socket communication principle
TASK03|概率论
報名開啟|飛槳黑客馬拉松第三期如約而至,久等啦
Big endian and little endian
金仓数据库 KingbaseES 插件identity_pwdexp
Apache ShenYu 入門
基于C语言的图书信息管理系统 课程论文+代码及可执行exe文件
Checking whether the double value is an integer - Swift - checking if a double value is an integer - swift
中国信通院沈滢:字体开源协议——OFL V1.1介绍及合规要点分析
Server rendering
Multiple environment variables
Apache ShenYu 入门