Class Solution
java.lang.Object
g0601_0700.s0667_beautiful_arrangement_ii.Solution
667 - Beautiful Arrangement II.<p>Medium</p>
<p>Given two integers <code>n</code> and <code>k</code>, construct a list <code>answer</code> that contains <code>n</code> different positive integers ranging from <code>1</code> to <code>n</code> and obeys the following requirement:</p>
<ul>
<li>Suppose this list is <code>answer = [a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>, … , a<sub>n</sub>]</code>, then the list <code>[|a<sub>1</sub> - a<sub>2</sub>|, |a<sub>2</sub> - a<sub>3</sub>|, |a<sub>3</sub> - a<sub>4</sub>|, … , |a<sub>n-1</sub> - a<sub>n</sub>|]</code> has exactly <code>k</code> distinct integers.</li>
</ul>
<p>Return <em>the list</em> <code>answer</code>. If there multiple valid answers, return <strong>any of them</strong>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 3, k = 1</p>
<p><strong>Output:</strong> [1,2,3] Explanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 3, k = 2</p>
<p><strong>Output:</strong> [1,3,2] Explanation: The [1,3,2] has three different positive integers ranging from 1 to 3, and the [2,1] has exactly 2 distinct integers: 1 and 2.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= k < n <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
constructArray
public int[] constructArray(int n, int k)
-