class Solution {
public List<List<Integer>> shiftGrid(int[][] grid, int k) {
List<List<Integer>> res = new ArrayList<>();
int m = grid.length, n = grid[0].length;
int[][] arr = new int[m][n];
for (int i = 0; i < m; i++){
for (int j = 0; j < n ;j++){
int temp = grid[i][j];
// 代表在当前行操作
if (k + j < n){
arr[i][j + k] = temp;
} else {
int x = j + k;
arr[(x / n + i ) % m][x % n] = temp;
}
}
}
for (int[] ints : arr) {
ArrayList<Integer> cur = new ArrayList<>();
for (int anInt : ints) {
cur.add(anInt);
}
res.add(cur);
}
return res;
}
}