Skip to content

Commit d05b2ca

Browse files
refactor 1260
1 parent 894aa8d commit d05b2ca

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ public static class Solution1 {
4141
public List<List<Integer>> shiftGrid(int[][] grid, int k) {
4242
int m = grid.length;
4343
int n = grid[0].length;
44-
int start = m * n - k % (m * n);
44+
int totalNumbers = m * n;
45+
int start = totalNumbers - k % totalNumbers;
4546
LinkedList<List<Integer>> result = new LinkedList<>();
46-
for (int i = start; i < m * n + start; i++) {
47-
int newIndex = i % (m * n);
48-
int newRow = newIndex / n;
49-
int newColumn = newIndex % n;
47+
for (int i = start; i < totalNumbers + start; i++) {
48+
int moveIndex = i % totalNumbers;
49+
int moveRow = moveIndex / n;
50+
int moveColumn = moveIndex % n;
5051
if ((i - start) % n == 0) {
5152
result.add(new ArrayList<>());
5253
}
53-
result.peekLast().add(grid[newRow][newColumn]);
54+
result.peekLast().add(grid[moveRow][moveColumn]);
5455
}
5556
return result;
5657
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy