#932

Beautiful Array

specialist · 650 · lc medium +30 · verified · 68.8% accepted · 1,153 likes · top 76%

Description

An array nums is beautiful if it is a permutation of [1, n] and no middle element is the arithmetic mean of two flanking elements — i.e., for no i < k < j does nums[i] + nums[j] == 2 * nums[k]. Given n, return any beautiful array of length n.

Example 1:

Input: n = 4
Output: [2,1,4,3]

Example 2:

Input: n = 5
Output: [3,1,2,5,4]

Code

1
2
3