File tree 2 files changed +38
-60
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder
2 files changed +38
-60
lines changed Original file line number Diff line number Diff line change @@ -5,31 +5,9 @@ public static class Solution1 {
5
5
public boolean isToeplitzMatrix (int [][] matrix ) {
6
6
int m = matrix .length ;
7
7
int n = matrix [0 ].length ;
8
- int i = 0 ;
9
- int j = 0 ;
10
- int sameVal = matrix [i ][j ];
11
- while (++i < m && ++j < n ) {
12
- if (matrix [i ][j ] != sameVal ) {
13
- return false ;
14
- }
15
- }
16
-
17
- for (i = 1 , j = 0 ; i < m ; i ++) {
18
- int tmpI = i ;
19
- int tmpJ = j ;
20
- sameVal = matrix [i ][j ];
21
- while (++tmpI < m && ++tmpJ < n ) {
22
- if (matrix [tmpI ][tmpJ ] != sameVal ) {
23
- return false ;
24
- }
25
- }
26
- }
27
- for (i = 0 , j = 1 ; j < n ; j ++) {
28
- int tmpJ = j ;
29
- int tmpI = i ;
30
- sameVal = matrix [tmpI ][tmpJ ];
31
- while (++tmpI < m && ++tmpJ < n ) {
32
- if (matrix [tmpI ][tmpJ ] != sameVal ) {
8
+ for (int i = 1 ; i < m ; i ++) {
9
+ for (int j = 1 ; j < n ; j ++) {
10
+ if (matrix [i ][j ] != matrix [i - 1 ][j - 1 ]) {
33
11
return false ;
34
12
}
35
13
}
Original file line number Diff line number Diff line change 1
1
package com .fishercoder ;
2
2
3
3
import com .fishercoder .solutions ._766 ;
4
- import org .junit .BeforeClass ;
5
- import org .junit .Test ;
4
+ import org .junit .jupiter . api . BeforeEach ;
5
+ import org .junit .jupiter . api . Test ;
6
6
7
- import static org .junit .Assert .assertEquals ;
7
+ import static org .junit .jupiter . api . Assertions .assertEquals ;
8
8
9
9
public class _766Test {
10
- private static _766 .Solution1 solution1 ;
11
- private static int [][] matrix ;
10
+ private static _766 .Solution1 solution1 ;
11
+ private static int [][] matrix ;
12
12
13
- @ BeforeClass
14
- public static void setup () {
15
- solution1 = new _766 .Solution1 ();
16
- }
13
+ @ BeforeEach
14
+ public void setup () {
15
+ solution1 = new _766 .Solution1 ();
16
+ }
17
17
18
- @ Test
19
- public void test1 () {
20
- matrix = new int [][] {
21
- {1 , 2 , 3 , 4 },
22
- {5 , 1 , 2 , 3 },
23
- {9 , 5 , 1 , 2 }
24
- };
25
- assertEquals (true , solution1 .isToeplitzMatrix (matrix ));
26
- }
18
+ @ Test
19
+ public void test1 () {
20
+ matrix = new int [][]{
21
+ {1 , 2 , 3 , 4 },
22
+ {5 , 1 , 2 , 3 },
23
+ {9 , 5 , 1 , 2 }
24
+ };
25
+ assertEquals (true , solution1 .isToeplitzMatrix (matrix ));
26
+ }
27
27
28
- @ Test
29
- public void test2 () {
30
- matrix = new int [][] {
31
- {1 , 2 },
32
- {2 , 2 },
33
- };
34
- assertEquals (false , solution1 .isToeplitzMatrix (matrix ));
35
- }
28
+ @ Test
29
+ public void test2 () {
30
+ matrix = new int [][]{
31
+ {1 , 2 },
32
+ {2 , 2 },
33
+ };
34
+ assertEquals (false , solution1 .isToeplitzMatrix (matrix ));
35
+ }
36
36
37
- @ Test
38
- public void test3 () {
39
- matrix = new int [][] {
40
- {1 , 2 , 3 , 4 , 5 , 9 },
41
- {5 , 1 , 2 , 3 , 4 , 5 },
42
- {9 , 5 , 1 , 2 , 3 , 4 }
43
- };
44
- assertEquals (true , solution1 .isToeplitzMatrix (matrix ));
45
- }
37
+ @ Test
38
+ public void test3 () {
39
+ matrix = new int [][]{
40
+ {1 , 2 , 3 , 4 , 5 , 9 },
41
+ {5 , 1 , 2 , 3 , 4 , 5 },
42
+ {9 , 5 , 1 , 2 , 3 , 4 }
43
+ };
44
+ assertEquals (true , solution1 .isToeplitzMatrix (matrix ));
45
+ }
46
46
}
You can’t perform that action at this time.
0 commit comments