diff --git b/toeplitzmatrix.py a/toeplitzmatrix.py new file mode 100644 index 0000000..0763bce --- /dev/null +++ a/toeplitzmatrix.py @@ -0,0 +1,37 @@ + +class Solution: + def isToeplitzMatrix(self, matrix): + pass + """ + :type matrix: List[List[int]] + :rtype: bool + + 解题思路:遍历每一个元素,同时比较这个元素和它右下角元素的值是否相等,如果不相等,直接返回false,停止遍历 + """ + + for i in range(len(matrix)-1): + for j in range(len(matrix[i])-1): + if (matrix[i + 1][j + 1] != matrix[i][j]): + return False + + return True + + + + + +if __name__ == "__main__": + solution = Solution() + + matrix = [ + [1, 2], + [2, 2] + ] + print(solution.isToeplitzMatrix(matrix)) + + matrix = [ + [1, 2, 3, 4], + [5, 1, 2, 3], + [9, 5, 1, 2] + ] + print(solution.isToeplitzMatrix(matrix)) \ No newline at end of file