当前位置:网站首页>牛客网:旋转数组
牛客网:旋转数组
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 KFS data centralized scenario (many to one) deployment
- Causes and solutions of over fitting
- 记一次有趣的逻辑SRC挖掘
- 16 enterprise architecture strategies
- Ladder Side-Tuning:预训练模型的“过墙梯”
- [maintain cluster case set] gaussdb query user space usage
- Checking whether the double value is an integer - Swift - checking if a double value is an integer - swift
- MySQL synchronous data configuration and shell script implementation
- SQL注入漏洞(绕过篇)
- 过拟合原因及解决
猜你喜欢

Apache ShenYu 入门

开源社邀请您参加OpenSSF开源安全线上研讨会

仿真与烧录程序有哪几种方式?(包含常用工具与使用方式)

Query method and interrupt method to realize USART communication

At 16:00 today, Mr. sunxiaoming, a researcher of the Institute of computing, Chinese Academy of Sciences, took you into the quantum world

Démarrer avec Apache shenyu

Double tampon transparent cryptage et décryptage basé sur le cadre minifilter

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

zabbix分布式系统监控

Upload and modify the use of avatars
随机推荐
GCC related
Software testing to avoid being dismissed during the probation period
Database Series: MySQL index optimization summary (comprehensive version)
【文件包含漏洞-04】经典面试题:已知某网站仅存在本地文件包含漏洞时,如何GetShell?
PHP如何提取字符串中的图片地址
过拟合原因及解决
16 enterprise architecture strategies
What are the functions of arm64 assembly that need attention?
Upload and modify the use of avatars
Big Endian 和 Little Endian
Handler、Message、Looper、MessageQueue
基于C语言的图书信息管理系统 课程论文+代码及可执行exe文件
[file inclusion vulnerability-04] classic interview question: how to getshell when a website is known to have only local file inclusion vulnerability?
16 种企业架构策略
CMU提出NLP新范式—重构预训练,高考英语交出134高分
Redis6笔记02 配置文件,发布和订阅,新数据类型,Jedis操作
金仓数据库 KingbaseES 插件identity_pwdexp
GaussDB 集群维护案例集-sql执行慢
scrapy+scrapyd+gerapy 爬虫调度框架
Gaussdb others scenarios with high memory