Beautiful Array LeetCode solution in C++
1class Solution {2public:3vector<int> beautifulArray(int n) {4vector<int> v = {1};56while (v.size() < n) {7vector<int> x;89for (auto c : v) {10if (c * 2 - 1 <= n) {11x.push_back(c * 2 - 1);12}13}1415for (auto d : v) {16if (d * 2 <= n) {17x.push_back(d * 2);18}19}20v = x;21}2223return v;24}25};