#include <deque> #include <vector> class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * 旋转数组 * @param n int整型 数组长度 * @param m int整型 右移距离 * @param a int整型vector 给定数组 * @return int整型vector */ vector<int> Rotatedarray(vector<int>& a,int s){ int t; for( int k = 0 ; k<s ; k++ ){ t = a.back(); auto i = a.begin(); a.insert(i,t); a.pop_back(); } return a; } vector<int> solve(int n, int m, vector<int>& a) { // write code here return Rotatedarray(a,m); } };
只要会把数组元素往后推一次,然后循环m次就行