Skip to content

Commit 9935212

Browse files
update 766
1 parent bf25eb0 commit 9935212

File tree

2 files changed

+38
-60
lines changed

2 files changed

+38
-60
lines changed

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

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
package com.fishercoder;
22

33
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;
66

7-
import static org.junit.Assert.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
88

99
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;
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
}

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