当前位置:网站首页>Niuke: rotation array
Niuke: rotation array
2022-06-25 11:24:00 【lsgoose】
This problem is done with array flipping , Didn't you think ...
It's amazing , From the example of the topic :
123456 Flip whole into 654321
Then we flip the front 2 Bit becomes 564321, After flipping 4 And the bits become 561234, Isn't that amazing ....
At first I thought of using circular shift to do ...
The answer is as follows :
class Solution {
public:
/**
* Rotated array
* @param n int integer The length of the array
* @param m int integer Shift right distance
* @param a int integer vector Given array
* @return int integer 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;
}
};
边栏推荐
- Hangzhou / Beijing neitui Ali Dharma academy recruits academic interns in visual generation (talent plan)
- Handler、Message、Looper、MessageQueue
- 金仓数据库 KingbaseES 插件identity_pwdexp
- 牛客网:分糖果问题
- SystemVerilog (XIII) - enumerate data types
- Network remote access using raspberry pie
- Very important very important very important very important very important very important very important very important very important
- 建造者模式
- 2022年PMP项目管理考试敏捷知识点(2)
- 基于Minifilter框架的双缓冲透明加解密驱动 课程论文+项目源码
猜你喜欢
Android之Kotlin语法详解与使用
基於Minifilter框架的雙緩沖透明加解密驅動 課程論文+項目源碼
What are the ways to simulate and burn programs? (including common tools and usage)
Socket communication principle
Redis6 note02 configuration file, publish and subscribe, new data type, jedis operation
Spark history server and event log details
JVM 原理简介
Detailed explanation of spark specification
网易开源的分布式存储系统 Curve 正式成为 CNCF 沙箱项目
Double tampon transparent cryptage et décryptage basé sur le cadre minifilter
随机推荐
牛客网:分糖果问题
Android: generic mapping analysis of gson and JSON in kotlin
动态规划解决股票问题(上)
try-catch-finally
Démarrer avec Apache shenyu
[shangyun boutique] energy saving and efficiency improvement! Accelerating the transformation of "intelligent manufacturing" in the textile industry
Kingbasees plug-in ftutilx of Jincang database
Vulnérabilité à l'injection SQL (contournement)
3 Questions par jour (3) - vérifier l'existence d'entiers et de leurs doubles
Shen Lu, China Communications Institute: police open source Protocol - ofl v1.1 Introduction and Compliance Analysis
Open source invites you to participate in the openssf Open Source Security Online Seminar
Technical practice and development trend of video conference all in one machine
MySQL synchronous data configuration and shell script implementation
scrapy+scrapyd+gerapy 爬虫调度框架
Big endian and little endian
Query method and interrupt method to realize USART communication
PHP如何提取字符串中的图片地址
金仓数据库 KingbaseES 插件force_view
COSCon'22 讲师征集令
开源社邀请您参加OpenSSF开源安全线上研讨会