标签:bsp vector ++ interval image class tor color img
class Solution { public: vector<int> constructArray(int n, int k) { vector<int> ret(n); ret[0] = 1; //构造k个不同的差值 for (int i = 1, interval = k; i <= k; ++i, --interval) ret[i] = i % 2 == 1 ? (ret[i - 1] + interval) : (ret[i - 1] - interval); //从k+1补到n for (int i = k + 1; i < n; ++i) ret[i] = i + 1; return ret; } };
LeetCode 667. 优美的排列 II Beautiful Arrangement II (Medium)
标签:bsp vector ++ interval image class tor color img
原文地址:https://www.cnblogs.com/ZSY-blog/p/12918909.html