Class Solution
java.lang.Object
g0501_0600.s0526_beautiful_arrangement.Solution
526 - Beautiful Arrangement.<p>Medium</p>
<p>Suppose you have <code>n</code> integers labeled <code>1</code> through <code>n</code>. A permutation of those <code>n</code> integers <code>perm</code> ( <strong>1-indexed</strong> ) is considered a <strong>beautiful arrangement</strong> if for every <code>i</code> (<code>1 <= i <= n</code>), <strong>either</strong> of the following is true:</p>
<ul>
<li><code>perm[i]</code> is divisible by <code>i</code>.</li>
<li><code>i</code> is divisible by <code>perm[i]</code>.</li>
</ul>
<p>Given an integer <code>n</code>, return <em>the <strong>number</strong> of the <strong>beautiful arrangements</strong> that you can construct</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 2</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<p>The first beautiful arrangement is [1,2]:</p>
<ul>
<li>
<p>perm[1] = 1 is divisible by i = 1</p>
</li>
<li>
<p>perm[2] = 2 is divisible by i = 2</p>
</li>
</ul>
<p>The second beautiful arrangement is [2,1]:</p>
<ul>
<li>
<p>perm[1] = 2 is divisible by i = 1</p>
</li>
<li>
<p>i = 2 is divisible by perm[2] = 1</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 1</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 15</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countArrangement
public int countArrangement(int n)
-