Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
homework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ligang
homework
Commits
4b1af0ab
Commit
4b1af0ab
authored
Jan 19, 2019
by
ligang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'第七次作业'
parent
3beb3747
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
07-homework-ligang/matrix.py
+29
-0
No files found.
07-homework-ligang/matrix.py
0 → 100644
View file @
4b1af0ab
#!/usr/bin/env python
#-*- coding:utf-8 - *-
#托普利茨矩阵
#如果一个矩阵的每一方向由左上到右下的对角线上具有相同元素,那么这个矩阵是托普利茨矩阵。
# 给定一个 M x N 的矩阵,当且仅当它是托普利茨矩阵时返回 True。
# 示例 1:输入: matrix = [[1,2,3,4], [5,1,2,3], [9,5,1,2]]
# 输出: True
# m*n矩阵
#注意
#说明: matrix 是一个包含整数的二维数组。
# matrix 的行数和列数均在 [1, 20]范围内。
# matrix[i][j] 包含的整数在 [0, 99]范围内。进阶:
class
Solution
:
def
isToeplitzMatrix
(
self
,
matrix
):
# m行
m
=
len
(
matrix
)
# n列
n
=
len
(
matrix
[
0
])
for
i
in
range
(
m
):
for
j
in
range
(
n
):
if
matrix
[
i
][
j
]
!=
matrix
[
i
+
1
][
j
+
1
]:
return
False
return
True
matrix
=
[[
1
,
2
,
3
,
4
],
[
5
,
1
,
2
,
3
],
[
9
,
5
,
1
,
2
]]
solu
=
Solution
()
solu
.
isToeplitzMatrix
(
matrix
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment