https://leetcode.com/problems/sign-of-the-product-of-an-array/
https://leetcode.com/problems/toeplitz-matrix/
https://leetcode.com/problems/divisor-game/
https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/
https://leetcode.com/problems/island-perimeter/
https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate/
https://leetcode.com/problems/unique-email-addresses/
https://leetcode.com/problems/next-greater-element-i/
https://leetcode.com/problems/toeplitz-matrix/
public boolean isToeplitzMatrix(int[][] matrix) {
List<Dot> dots = new ArrayList<>();
for(int i=0 ; i<matrix.length ; i++) {
for(int j=0 ; j<matrix[i].length ; j++) {
dots.add(new Dot(i, j, matrix[i][j]));
}
}
//yMinX 가 같은수끼리 벨류가 같은지 검증하고 하나라도 틀리면 실패
int difEnd = Math.min(matrix.length,matrix[0].length)-1;//단축길이 -1
int difStart = Math.max(matrix.length,matrix[0].length)-2;//장축길이 -2
int dif = difStart;
int validator = -1;
while (dif != difEnd ) {
for(int i=0 ; i<dots.size() ; i++) {
Dot dot = dots.get(i);
if(dot.yMinX == dif) {
if(validator == -1) {
validator = dot.value;
}
else {
if(validator != dot.value) {
return false;
}
}
}
}
dif++;
}
return true;
}
class Dot {
int yMinX;
int y;
int x;
int value;
public Dot(int y, int x,int value) {
this.y = y;
this.x = x;
this.value = value;
this.yMinX = this.y - this.x;
}
}