Skip to content

Commit 4249957

Browse files
committed
change while loop to for loop
1 parent 30c1516 commit 4249957

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def rotate_matrix_in_place(
4747
num_rotations = 4
4848
if N == 0 or N == 1:
4949
return matrix
50-
col = start_col
51-
while True:
50+
for col in range(start_col, N - 1 + start_col):
5251
rotated_row = start_row
5352
rotated_col = col
5453
temp_new = matrix[start_row][col]
@@ -61,9 +60,6 @@ def rotate_matrix_in_place(
6160
# store value at newly computed indices
6261
temp_new = matrix[rotated_row][rotated_col]
6362
matrix[rotated_row][rotated_col] = temp
64-
if col - start_col >= N - 2:
65-
break
66-
col = col + 1
6763
return rotate_matrix_in_place(matrix, start_row + 1, start_col + 1, N - 2)
6864

6965

0 commit comments

Comments
 (0)