-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0766_Toeplitz_Matrix.py
More file actions
33 lines (27 loc) · 894 Bytes
/
0766_Toeplitz_Matrix.py
File metadata and controls
33 lines (27 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution:
def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
n_row = len(matrix)
n_col = len(matrix[0])
# Upper triagle
for index_col in range(n_col):
num = matrix[0][index_col]
col = index_col
row = 0
while col < n_col and row < n_row:
sub_num = matrix[row][col]
if not num == sub_num:
return False
col += 1
row += 1
# Lower Triangle
for index_row in range(1, n_row):
num = matrix[index_row][0]
col = 0
row = index_row
while col < n_col and row < n_row:
sub_num = matrix[row][col]
if not num == sub_num:
return False
col += 1
row += 1
return Truev