Skip to content

Commit f3a4feb

Browse files
refactor 1260
1 parent d3db213 commit f3a4feb

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

src/main/java/com/fishercoder/solutions/_1260.java

+3-32
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,11 @@
44
import java.util.LinkedList;
55
import java.util.List;
66

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-
* */
387
public class _1260 {
398
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+
*/
4112
public List<List<Integer>> shiftGrid(int[][] grid, int k) {
4213
int m = grid.length;
4314
int n = grid[0].length;

0 commit comments

Comments
 (0)