Skip to content

Commit e2c218b

Browse files
committed
Update beautiful_arrangement.py
2 parents 8e9407b + 342669a commit e2c218b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

dynamic_programming/beautiful_arrangement.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
class BeautifulArrange:
1414
# funtion call; n is the size of the permutation (numbers 1..n)
1515
def countarrangement(self, n: int) -> int:
16-
1716
self.count = 0
1817
"""
19-
We initialize a counter to record how many valid arrangements we find.
18+
We initialize a counter to record how many valid arrangements we find.
2019
Using self.count lets the nested function modify it without nonlocal.
2120
"""
22-
21+
2322
used = [False] * (n + 1)
2423
"""
25-
A boolean list to mark which numbers have
24+
A boolean list to mark which numbers have
2625
already been placed in the permutation.
2726
"""
2827

@@ -33,7 +32,7 @@ def backtrack(pos):
3332
We try to assign a number to position pos.
3433
"""
3534
if pos > n:
36-
self.count += 1
35+
self.count += 1
3736
# We found a complete valid arrangement, so increment the total count.
3837
return
3938
for num in range(

0 commit comments

Comments
 (0)