Skip to content

Commit 4ce9afe

Browse files
committed
update to concise way of swapping values
1 parent 37372aa commit 4ce9afe

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ def _perform_full_rotation(matrix: List[List[int]], row: int, col: int, M: int):
4040
rotated_col = col
4141
temp_new = matrix[row][col]
4242
for r in range(0, num_rotations):
43-
temp = temp_new
4443
# compute new rotated indices
4544
prev_col = rotated_col
4645
rotated_col = M - 1 - rotated_row + (start_row * 2) # offset to account for reduced N
4746
rotated_row = prev_col
4847
# store value at newly computed indices
49-
temp_new = matrix[rotated_row][rotated_col]
50-
matrix[rotated_row][rotated_col] = temp
48+
temp_new, matrix[rotated_row][rotated_col] = matrix[rotated_row][rotated_col], temp_new
5149

5250

5351
def rotate_matrix_in_place(

0 commit comments

Comments
 (0)