C++ O(n) Array Solution


#1

vector Solution::rotateArray(vector &A, int B)
{
vector ret;
B=B%A.size();
for (int i = B; i < A.size(); i++)
{
ret.push_back(A[i]);
}
for(int i=0;i<B;i++)
ret.push_back(A[i]);

return ret; 

}


#2

vector Solution::rotateArray(vector &A, int B) {
vector ret;
B=B%A.size();
for (int i = B; i < A.size(); i++) {
ret.push_back(A[i]);
}
for(int j=0;j<B;j++)
{
ret.push_back(A[j]);
}
return ret;
}