# LeetCode 932. Beautiful Array [LeetCode 932. Beautiful Array]() (<font color=#FFB800>Medium</font> 39.6%) <!-- (<font color=#00AF9B>Easy</font> 53.8%) (<font color=#FFB800>Medium</font> 39.6%) (<font color=#FF375F>Hard</font>) --> - 限制 : <ul> <li><code>1 <= n <= 1000</code></li> </ul> - Solution - 時間複雜度: $O(nlogn)$ - 空間複雜度: $O(n)$ - 程式碼 ```c++= class Solution { public: vector<int> beautifulArray(int n) { vector<int> result = {1}; while (result.size() < n) { vector<int> temp; for (int i : result) { if (i * 2 - 1 <= n) temp.push_back(i * 2 - 1); } for (int i : result) { if (i * 2 <= n) temp.push_back(i * 2); } result = temp; // 更新結果 } return result; } }; ``` </details>
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.