Skip to content

Commit 37372aa

Browse files
committed
remove optional parameter and update comments to submatrix
1 parent 1af2158 commit 37372aa

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ def rotate_matrix(matrix: List[List[int]]) -> List[List[int]]:
2525
return rotated
2626

2727

28-
def _perform_full_rotation(matrix: List[List[int]], row: int, col: int, N: Optional[int] = None):
28+
def _perform_full_rotation(matrix: List[List[int]], row: int, col: int, M: int):
2929
"""
3030
Helper function that performs four 90 degree rotations starting at row, col.
31-
:param matrix: an NxN matrix
31+
:param matrix: an MxM sub-matrix out of an NxN matrix
3232
:param row: starting row
3333
:param col: starting column
34-
:param N: size of matrix
34+
:param M: size of sub-matrix
3535
:return:
3636
"""
37-
if N is None:
38-
N = len(matrix)
3937
num_rotations = 4
4038
start_row = row
4139
rotated_row = row
@@ -45,7 +43,7 @@ def _perform_full_rotation(matrix: List[List[int]], row: int, col: int, N: Optio
4543
temp = temp_new
4644
# compute new rotated indices
4745
prev_col = rotated_col
48-
rotated_col = N - 1 - rotated_row + (start_row * 2) # offset to account for reduced N
46+
rotated_col = M - 1 - rotated_row + (start_row * 2) # offset to account for reduced N
4947
rotated_row = prev_col
5048
# store value at newly computed indices
5149
temp_new = matrix[rotated_row][rotated_col]

0 commit comments

Comments
 (0)