Skip to content

Commit 5eb30e3

Browse files
refactor 566
1 parent 53c1e8d commit 5eb30e3

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,24 @@
3737
*/
3838
public class _566 {
3939

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;
5449
}
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;
5558
}
56-
return result;
5759
}
58-
5960
}

src/test/java/com/fishercoder/_566Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Created by fishercoder on 4/29/17.
1111
*/
1212
public class _566Test {
13-
private static _566 test;
13+
private static _566.Solution1 solution1;
1414
private static int[][] expected;
1515
private static int[][] actual;
1616
private static int[][] nums;
@@ -19,7 +19,7 @@ public class _566Test {
1919

2020
@BeforeClass
2121
public static void setup() {
22-
test = new _566();
22+
solution1 = new _566.Solution1();
2323
}
2424

2525
@Test
@@ -31,7 +31,7 @@ public void test1() {
3131
r = 1;
3232
c = 4;
3333
expected = new int[][]{{1, 2, 3, 4}};
34-
actual = test.matrixReshape(nums, r, c);
34+
actual = solution1.matrixReshape(nums, r, c);
3535
assertArrayEquals(expected, actual);
3636
}
3737
}

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