C++ A simple solution
\n\nstatic const auto io_sync_off = [](){\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    return nullptr;\n}();\nclass Solution {\npublic:\n    ve
```\n\nstatic const auto io_sync_off = [](){\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    return nullptr;\n}();\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k){         \n         int l=2,r=n;\n         vector<int> res; res.push_back(1);\n         if(k==1){\n             for(int i=l;i<=r;i++)\n                 res.push_back(i);\n             return res;             \n         }\n         int time=1;\n         while(l<=r)\n         {\n             if(time&1)             \n                 //\u5947\u6570\n                 res.push_back(r--);\n             else\n                 res.push_back(l++);\n             k--;\n             time++;\n             if(k==1){\n                 if(time&1)\n                 for(int i=l;i<=r;i++)\n                 res.push_back(i);\n                 else\n                 for(int i=r;i>=l;i--)\n                 res.push_back(i);\n                 return res;          \n             }                 \n         }\n         return res;\n    }\n};\n```
[]