File tree Expand file tree Collapse file tree 2 files changed +38
-60
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 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 {
55 public boolean isToeplitzMatrix (int [][] matrix ) {
66 int m = matrix .length ;
77 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 ]) {
3311 return false ;
3412 }
3513 }
Original file line number Diff line number Diff line change 11package com .fishercoder ;
22
33import 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 ;
66
7- import static org .junit .Assert .assertEquals ;
7+ import static org .junit .jupiter . api . Assertions .assertEquals ;
88
99public class _766Test {
10- private static _766 .Solution1 solution1 ;
11- private static int [][] matrix ;
10+ private static _766 .Solution1 solution1 ;
11+ private static int [][] matrix ;
1212
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+ }
1717
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+ }
2727
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+ }
3636
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+ }
4646}
You can’t perform that action at this time.
0 commit comments