1 | 描述 |
简单题,直接代码:
python1
2
3
4
5
6
7
8
9
10
11
12class Solution:
"""
@param matrix: the given matrix
@return: True if and only if the matrix is Toeplitz
"""
def isToeplitzMatrix(self, matrix):
# Write your code here
for i in range(1,len(matrix)):
for j in range(1,len(matrix[0])):
if matrix[i][j]!=matrix[i-1][j-1]:
return False
return True
java1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19public class Solution {
/**
* @param matrix: the given matrix
* @return: True if and only if the matrix is Toeplitz
*/
public boolean isToeplitzMatrix(int[][] matrix) {
// Write your code here
int m = matrix.length;
int n = matrix[0].length;
for(int i=1;i<m;i++){
for(int j=1;j<n;j++){
if(matrix[i][j]!=matrix[i-1][j-1]){
return false;
}
}
}
return true;
}
}