FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/rotate-image.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
rotate-image.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (23 loc) · 817 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
rotate-image.py
Copy path
File metadata and controls
29 lines (23 loc) · 817 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# Time: O(n^2)
# Space: O(1)
class
Solution
(
object
):
# @param matrix, a list of lists of integers
# @return a list of lists of integers
def
rotate
(
self
,
matrix
):
n
=
len
(
matrix
)
# anti-diagonal mirror
for
i
in
xrange
(
n
):
for
j
in
xrange
(
n
-
i
):
matrix
[
i
][
j
],
matrix
[
n
-
1
-
j
][
n
-
1
-
i
]
=
matrix
[
n
-
1
-
j
][
n
-
1
-
i
],
matrix
[
i
][
j
]
# horizontal mirror
for
i
in
xrange
(
n
/
2
):
for
j
in
xrange
(
n
):
matrix
[
i
][
j
],
matrix
[
n
-
1
-
i
][
j
]
=
matrix
[
n
-
1
-
i
][
j
],
matrix
[
i
][
j
]
return
matrix
# Time: O(n^2)
# Space: O(n^2)
class
Solution2
(
object
):
# @param matrix, a list of lists of integers
# @return a list of lists of integers
def
rotate
(
self
,
matrix
):
return
[
list
(
reversed
(
x
))
for
x
in
zip
(
*
matrix
)]
Back
|
FazBrowse Home
|
New Git URL