|
4 | 4 | import java.util.LinkedList; |
5 | 5 | import java.util.List; |
6 | 6 |
|
7 | | -/** |
8 | | - * 1260. Shift 2D Grid |
9 | | - * |
10 | | - * Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. |
11 | | - * |
12 | | - * In one shift operation: |
13 | | - * Element at grid[i][j] becomes at grid[i][j + 1]. |
14 | | - * Element at grid[i][n - 1] becomes at grid[i + 1][0]. |
15 | | - * Element at grid[n - 1][n - 1] becomes at grid[0][0]. |
16 | | - * Return the 2D grid after applying shift operation k times. |
17 | | - * |
18 | | - * Example 1: |
19 | | - * Input: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1 |
20 | | - * Output: [[9,1,2],[3,4,5],[6,7,8]] |
21 | | - * |
22 | | - * Example 2: |
23 | | - * Input: grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4 |
24 | | - * Output: [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]] |
25 | | - * |
26 | | - * Example 3: |
27 | | - * Input: grid = [[1,2,3],[4,5,6],[7,8,9]], k = 9 |
28 | | - * Output: [[1,2,3],[4,5,6],[7,8,9]] |
29 | | - * |
30 | | - * Constraints: |
31 | | - * m == grid.length |
32 | | - * n == grid[i].length |
33 | | - * 1 <= m <= 50 |
34 | | - * 1 <= n <= 50 |
35 | | - * -1000 <= grid[i][j] <= 1000 |
36 | | - * 0 <= k <= 100 |
37 | | - * */ |
38 | 7 | public class _1260 { |
39 | 8 | public static class Solution1 { |
40 | | - /**credit: https://leetcode.com/problems/shift-2d-grid/discuss/431102/JavaPython-3-simple-code-using-mod*/ |
| 9 | + /** |
| 10 | + * credit: https://leetcode.com/problems/shift-2d-grid/discuss/431102/JavaPython-3-simple-code-using-mod |
| 11 | + */ |
41 | 12 | public List<List<Integer>> shiftGrid(int[][] grid, int k) { |
42 | 13 | int m = grid.length; |
43 | 14 | int n = grid[0].length; |
|
0 commit comments