Package g0901_1000.s0932_beautiful_array
Class Solution
- java.lang.Object
-
- g0901_1000.s0932_beautiful_array.Solution
-
public class Solution extends Object
932 - Beautiful Array.Medium
An array
nums
of lengthn
is beautiful if:nums
is a permutation of the integers in the range[1, n]
.- For every
0 <= i < j < n
, there is no indexk
withi < k < j
where2 * nums[k] == nums[i] + nums[j]
.
Given the integer
n
, return any beautiful arraynums
of lengthn
. There will be at least one valid answer for the givenn
.Example 1:
Input: n = 4
Output: [2,1,4,3]
Example 2:
Input: n = 5
Output: [3,1,2,5,4]
Constraints:
1 <= n <= 1000
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
beautifulArray(int n)
-