Commit fc91be71 by yangpengflag

Initial commit

parents
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment