blob: b6b06f2ed23d694cd2957015f884e71be611b48e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<vector<int>> shiftGrid(vector<vector<int>> &grid, int k) {
int n = grid.size(), m = grid[0].size();
vector<vector<int>> ans(n, vector<int>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
int newJ = (j + k) % m;
int newI = (i + (j + k) / m) % n;
ans[newI][newJ] = grid[i][j];
}
return ans;
}
};
int main() {}
|