Skip to content

Commit bf5e802

Browse files
authored
Create determine-whether-matrix-can-be-obtained-by-rotation.py
1 parent f480360 commit bf5e802

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(m * n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def findRotation(self, mat, target):
6+
"""
7+
:type mat: List[List[int]]
8+
:type target: List[List[int]]
9+
:rtype: bool
10+
"""
11+
checks = [lambda i, j: mat[i][j] == target[i][j],
12+
lambda i, j: mat[i][j] == target[j][-1-i],
13+
lambda i, j: mat[i][j] == target[-1-i][-1-j],
14+
lambda i, j: mat[i][j] == target[-1-j][i]]
15+
traverse = lambda check: all(check(i, j) for i in xrange(len(mat)) for j in xrange(len(mat[0])))
16+
return any(traverse(check) for check in checks)

0 commit comments

Comments
 (0)