@@ -39,11 +39,10 @@ def _perform_full_rotation(matrix: List[List[int]], row: int, col: int, M: int):
39
39
rotated_row = row
40
40
rotated_col = col
41
41
temp_new = matrix [row ][col ]
42
- for r in range (0 , num_rotations ):
42
+ for _ in range (0 , num_rotations ):
43
43
# 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
47
46
# store value at newly computed indices
48
47
temp_new , matrix [rotated_row ][rotated_col ] = matrix [rotated_row ][rotated_col ], temp_new
49
48
@@ -56,12 +55,10 @@ def rotate_matrix_in_place(matrix: List[List[int]]) -> List[List[int]]:
56
55
:param matrix: an NxN matrix
57
56
:return: the input matrix, but rotated
58
57
"""
59
- start_row = 0
60
58
N = len (matrix )
61
- for n in range (N , 1 , - 2 ):
59
+ for start_row , n in enumerate ( range (N , 1 , - 2 ) ):
62
60
for col in range (start_row , n - 1 + start_row ):
63
61
_perform_full_rotation (matrix , start_row , col , n )
64
- start_row += 1
65
62
return matrix
66
63
67
64
0 commit comments