MJay

932 본문

Programming/LeetCode

932

MJSon 2019. 10. 30. 10:32

For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such that:

For every i < j, there is no k with i < k < j such that A[k] * 2 = A[i] + A[j].

Given N, return any beautiful array A.  (It is guaranteed that one exists.)

 

Example 1:

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

Example 2:

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

 

Note:

  • 1 <= N <= 1000

접근법

 

천재분한테 배워갑니다..

 

odd even으로도 divide and conquer

 

nlogn 이다.

 

 2O(n/2) + logn

 

개쩐다.. 재밌다..

'Programming > LeetCode' 카테고리의 다른 글

270  (0) 2019.10.31
931  (0) 2019.10.31
959  (0) 2019.10.30
1140  (0) 2019.10.29
877  (0) 2019.10.28