11"""
2- Suppose you have n integers labeled 1 through n.
2+ Suppose you have n integers labeled 1 through n.
33A permutation of those n integers
4- perm (1-indexed) is considered a
4+ perm (1-indexed) is considered a
55"beautiful arrangement" if for every i (1 <= i <= n),
66either of the following is true:
77
88-> perm[i] is divisible by i.
99-> i is divisible by perm[i].
10- Given an integer n, return the number of the
10+ Given an integer n, return the number of the
1111"beautiful arrangements" that you can construct.
1212
1313"""
@@ -19,9 +19,9 @@ class BeautifulArrange:
1919 def countarrangement (self , n : int ) -> int :
2020 self .count = 0
2121 """
22- We initialize a counter to record how
22+ We initialize a counter to record how
2323 many valid arrangements we find.
24- Using self.count lets the nested
24+ Using self.count lets the nested
2525 function modify it without nonlocal.
2626 """
2727
@@ -34,7 +34,7 @@ def countarrangement(self, n: int) -> int:
3434 def backtrack (pos ):
3535 """
3636 Define the recursive backtracking function.
37- pos is the current position in the
37+ pos is the current position in the
3838 permutation we are filling (1-indexed).
3939 We try to assign a number to position pos.
4040 """
@@ -47,9 +47,9 @@ def backtrack(pos):
4747 ): # Try every candidate number num for the current position pos.
4848 """
4949 Two checks in one:
50- 1. not used[num] — the number num has
50+ 1. not used[num] — the number num has
5151 not been placed yet (we can use it).
52- 2. (num % pos == 0 or pos % num == 0) —
52+ 2. (num % pos == 0 or pos % num == 0) —
5353 the beautiful-arrangement condition:
5454 either num divides pos or pos divides num.
5555 If both are true, num is a valid choice for pos.
0 commit comments