classSolution: """ @param N: The number of integers @return: The number of beautiful arrangements you can construct """ defcountArrangement(self, N): # Write your code here self.ans = 0 defcompute(unvisited, index): if len(unvisited) == 0: self.ans += 1 return for i in range(len(unvisited)): s = unvisited[i] if s % index == 0or index % s == 0: unvisit = unvisited[:i] + unvisited[i+1:] compute(unvisit, index + 1)
n = list(range(1, N + 1)) compute(n, 1) return self.ans