0667.cpp (335B)
1 class Solution { 2 public: 3 vector<int> constructArray(int n, int k) const { 4 vector<int> res(n); 5 int idx = 0; 6 for (int i = 1; i < n - k; i++) 7 res[idx++] = i; 8 for (int i = 0; i <= k; i++) { 9 res[idx++] = i % 2 ? n - i / 2 : n - k + i / 2; 10 } 11 return res; 12 } 13 };