Skip to content

Commit

Permalink
Time: 20 ms (96.30%), Space: 14 MB (40.46%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
gkapelyushok committed Apr 11, 2022
1 parent 894789c commit 5626742
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 1260-shift-2d-grid/1260-shift-2d-grid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public:
vector<vector<int>> shiftGrid(vector<vector<int>>& grid, int k) {
int n = grid.size();
int m = grid[0].size();
vector<vector<int>> result(n, vector<int>(m));
for (int i = 0; i < n * m; i++) {
result[(i + k) % (n * m) / m][(i + k) % (n * m) % m] = grid[i / m][i % m];
}
return result;
}
};

0 comments on commit 5626742

Please sign in to comment.