Skip to content

Commit b70aa2c

Browse files
author
Partho Biswas
committed
48_Rotate_Image
1 parent dded7b6 commit b70aa2c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ I have solved quite a number of problems from several topics. See the below tabl
151151
|44| [41. First Missing Positive](https://tinyurl.com/tfewwtv)| [Python](https://tinyurl.com/wu6rdaw/41_First_Missing_Positive.py)| --- | Hard | Cyclic Sort, Very important |
152152
|45| **[939. Minimum Area Rectangle](https://tinyurl.com/tcr34w3)** | [Python](https://tinyurl.com/wu6rdaw/939_Minimum_Area_Rectangle.py)| [Art 1](https://tinyurl.com/wfgjaf3) | Medium | Hash and Set, Very important |
153153
|46| **[359. Logger Rate Limiter](https://tinyurl.com/tcr34w3)** | [Python](https://tinyurl.com/wu6rdaw/359_Logger_Rate_Limiter.py)| --- | Easy | Hash and Set, Very important |
154+
|47| **[48. Rotate Image](https://tinyurl.com/yy3z9hab)** | [Python](https://tinyurl.com/wu6rdaw/48_Rotate_Image.py)| [Must](https://tinyurl.com/tr62top), [Vid 1](https://tinyurl.com/uhnruzt) | Medium | Very important |
154155

155156

156157
</p>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Official Sol: https://tinyurl.com/rtyo3wq
2+
class Solution(object):
3+
def rotate(self, matrix):
4+
"""
5+
:type matrix: List[List[int]]
6+
:rtype: None Do not return anything, modify matrix in-place instead.
7+
"""
8+
row, col = len(matrix), len(matrix[0])
9+
10+
# transpose matrix
11+
for currRow in range(row):
12+
for currCol in range(currRow, col):
13+
matrix[currRow][currCol], matrix[currCol][currRow] = matrix[currCol][currRow], matrix[currRow][currCol]
14+
15+
# reverse each row
16+
for currRow in range(row):
17+
matrix[currRow].reverse()
18+
return matrix
19+
20+
21+
22+
23+
24+
# Source: https://tinyurl.com/tr62top
25+
class Solution(object):
26+
def rotate(self, matrix):
27+
"""
28+
:type matrix: List[List[int]]
29+
:rtype: None Do not return anything, modify matrix in-place instead.
30+
"""
31+
row, col = len(matrix), len(matrix[0])
32+
33+
firtRow, lastRow = 0, row - 1
34+
while firtRow < lastRow:
35+
matrix[firtRow] , matrix[lastRow] = matrix[lastRow], matrix[firtRow]
36+
firtRow += 1
37+
lastRow -= 1
38+
39+
# transpose matrix
40+
for currRow in range(row):
41+
for currCol in range(currRow, col):
42+
matrix[currRow][currCol], matrix[currCol][currRow] = matrix[currCol][currRow], matrix[currRow][currCol]
43+
44+
return matrix

0 commit comments

Comments
 (0)