File tree 1 file changed +7
-6
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -41,16 +41,17 @@ public static class Solution1 {
41
41
public List <List <Integer >> shiftGrid (int [][] grid , int k ) {
42
42
int m = grid .length ;
43
43
int n = grid [0 ].length ;
44
- int start = m * n - k % (m * n );
44
+ int totalNumbers = m * n ;
45
+ int start = totalNumbers - k % totalNumbers ;
45
46
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 ;
50
51
if ((i - start ) % n == 0 ) {
51
52
result .add (new ArrayList <>());
52
53
}
53
- result .peekLast ().add (grid [newRow ][ newColumn ]);
54
+ result .peekLast ().add (grid [moveRow ][ moveColumn ]);
54
55
}
55
56
return result ;
56
57
}
You can’t perform that action at this time.
0 commit comments