Skip to content

Commit 5c34387

Browse files
committed
minor nit updates
1 parent 4016fd3 commit 5c34387

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Python/chapter01/1.7 - Rotate Matrix/miguel_1.7_sol.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ def _perform_full_rotation(matrix: List[List[int]], row: int, col: int, M: int):
3939
rotated_row = row
4040
rotated_col = col
4141
temp_new = matrix[row][col]
42-
for r in range(0, num_rotations):
42+
for _ in range(0, num_rotations):
4343
# compute new rotated indices
44-
prev_col = rotated_col
45-
rotated_col = M - 1 - rotated_row + (start_row * 2) # offset to account for reduced N
46-
rotated_row = prev_col
44+
# (start_row * 2) is an offset to account for reduced M
45+
rotated_col, rotated_row = M - 1 - rotated_row + (start_row * 2), rotated_col
4746
# store value at newly computed indices
4847
temp_new, matrix[rotated_row][rotated_col] = matrix[rotated_row][rotated_col], temp_new
4948

@@ -56,12 +55,10 @@ def rotate_matrix_in_place(matrix: List[List[int]]) -> List[List[int]]:
5655
:param matrix: an NxN matrix
5756
:return: the input matrix, but rotated
5857
"""
59-
start_row = 0
6058
N = len(matrix)
61-
for n in range(N, 1, -2):
59+
for start_row, n in enumerate(range(N, 1, -2)):
6260
for col in range(start_row, n - 1 + start_row):
6361
_perform_full_rotation(matrix, start_row, col, n)
64-
start_row += 1
6562
return matrix
6663

6764

0 commit comments

Comments
 (0)