# 0667. Beautiful Arrangement II ###### tags: `Leetcode` `Medium` `Greedy` Link: https://leetcode.com/problems/beautiful-arrangement-ii/description/ ## 思路 思路参考[这里](https://leetcode.com/problems/beautiful-arrangement-ii/solutions/106948/c-java-clean-code-4-liner/) 先一小一大间隔排序 然后如果```k=1```了就直接把剩的数字按顺序放上 观察规律可知如果k是偶数 先放大的 反之放小的 ## Code ```java= class Solution { public int[] constructArray(int n, int k) { int[] ans = new int[n]; int l = 1, r = n; for(int i=0; i<n; i++){ if(k>1){ if(k%2!=0) ans[i] = l++; else ans[i] = r--; k--; } else ans[i] = l++; } return ans; } } ```