Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Created September 12, 2017 04:25
class Solution {
public:
vector<int> constructArray(int n, int k) {
if(n < k + 1)return {};
vector<int> res(n, 0);
int i = 1, j = k + 1;
while(i < j)
{
res[k + 1 - (j - i + 1)] = i;
++i;
res[k + 1 - (j - i + 1)] = j;
--j;
}
if(i == j)
res[k] = i;
for(int i = k + 1; i < n; ++i)
res[i] = i + 1;
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment