Class Solution

java.lang.Object
g0901_1000.s0932_beautiful_array.Solution

public class Solution extends Object
932 - Beautiful Array.<p>Medium</p> <p>An array <code>nums</code> of length <code>n</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>nums</code> is a permutation of the integers in the range <code>[1, n]</code>.</li> <li>For every <code>0 <= i < j < n</code>, there is no index <code>k</code> with <code>i < k < j</code> where <code>2 * nums[k] == nums[i] + nums[j]</code>.</li> </ul> <p>Given the integer <code>n</code>, return <em>any <strong>beautiful</strong> array</em> <code>nums</code> <em>of length</em> <code>n</code>. There will be at least one valid answer for the given <code>n</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 4</p> <p><strong>Output:</strong> [2,1,4,3]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 5</p> <p><strong>Output:</strong> [3,1,2,5,4]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • beautifulArray

      public int[] beautifulArray(int n)