-
Notifications
You must be signed in to change notification settings - Fork 2
/
1886.py
52 lines (44 loc) · 1.42 KB
/
1886.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# [ LeetCode ] 1886. Determine Whether Matrix Can Be Obtained By Rotation
def solution(mat: list[list[int]], target: list[list[int]]) -> bool:
def rotate(arr: list[list[int]]) -> None:
for i in range(len(arr)):
for j in range(i, len(arr[0])):
arr[i][j], arr[j][i] = arr[j][i], arr[i][j]
for i in range(len(arr)):
for j in range(len(arr) // 2):
arr[i][j], arr[i][len(arr)-j-1] \
= arr[i][len(arr)-j-1], arr[i][j]
count: int = 0
while count <= 3:
if mat == target:
return True
else:
rotate(arr=mat)
count += 1
return False
if __name__ == "__main__":
cases: list[dict[str, dict[str, list[list[int]]] | bool]] = [
{
"input": {
"mat": [[0, 1],[1, 0]],
"target": [[1, 0],[0, 1]]
},
"output": True,
},
{
"input": {
"mat": [[0, 1],[1, 1]],
"target": [[1, 0],[0, 1]]
},
"output": False,
},
{
"input": {
"mat": [[0, 0, 0],[0, 1, 0],[1, 1, 1]],
"target": [[1, 1, 1],[0, 1, 0],[0, 0, 0]]
},
"output": True,
}
]
for case in cases:
assert case["output"] == solution(**case["input"])