File tree 2 files changed +20
-19
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder 2 files changed +20
-19
lines changed Original file line number Diff line number Diff line change 37
37
*/
38
38
public class _566 {
39
39
40
- public int [][] matrixReshape (int [][] nums , int r , int c ) {
41
- if (nums == null || nums .length == 0 ) {
42
- return nums ;
43
- }
44
- int m = nums .length ;
45
- int n = nums [0 ].length ;
46
- if (r * c > m * n ) {
47
- return nums ;
48
- }
49
- int k = 0 ;
50
- int [][] result = new int [r ][c ];
51
- for (int i = 0 ; i < r ; i ++) {
52
- for (int j = 0 ; j < c ; j ++, k ++) {
53
- result [i ][j ] = nums [k / n ][k % n ];
40
+ public static class Solution1 {
41
+ public int [][] matrixReshape (int [][] nums , int r , int c ) {
42
+ if (nums == null || nums .length == 0 ) {
43
+ return nums ;
44
+ }
45
+ int m = nums .length ;
46
+ int n = nums [0 ].length ;
47
+ if (r * c > m * n ) {
48
+ return nums ;
54
49
}
50
+ int k = 0 ;
51
+ int [][] result = new int [r ][c ];
52
+ for (int i = 0 ; i < r ; i ++) {
53
+ for (int j = 0 ; j < c ; j ++, k ++) {
54
+ result [i ][j ] = nums [k / n ][k % n ];
55
+ }
56
+ }
57
+ return result ;
55
58
}
56
- return result ;
57
59
}
58
-
59
60
}
Original file line number Diff line number Diff line change 10
10
* Created by fishercoder on 4/29/17.
11
11
*/
12
12
public class _566Test {
13
- private static _566 test ;
13
+ private static _566 . Solution1 solution1 ;
14
14
private static int [][] expected ;
15
15
private static int [][] actual ;
16
16
private static int [][] nums ;
@@ -19,7 +19,7 @@ public class _566Test {
19
19
20
20
@ BeforeClass
21
21
public static void setup () {
22
- test = new _566 ();
22
+ solution1 = new _566 . Solution1 ();
23
23
}
24
24
25
25
@ Test
@@ -31,7 +31,7 @@ public void test1() {
31
31
r = 1 ;
32
32
c = 4 ;
33
33
expected = new int [][]{{1 , 2 , 3 , 4 }};
34
- actual = test .matrixReshape (nums , r , c );
34
+ actual = solution1 .matrixReshape (nums , r , c );
35
35
assertArrayEquals (expected , actual );
36
36
}
37
37
}
You can’t perform that action at this time.
0 commit comments