-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLC_1260.cpp
More file actions
25 lines (25 loc) · 725 Bytes
/
LC_1260.cpp
File metadata and controls
25 lines (25 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
public:
vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {
int i,j,m=grid.size(),n=grid[0].size(),ind;
vector<vector<int>>res(m,vector<int>(n));
res=grid;
for(ind=0;ind<k;ind++)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if((i<m) && (j+1<n))
res[i][j+1]=grid[i][j];
else if((i+1<m) && (j==n-1))
res[i+1][0]=grid[i][j];
else if((i==m-1) && (j==n-1))
res[0][0]=grid[i][j];
}
}
grid=res;
}
return res;
}
};