Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
beautiful-array.cpp 632 Bytes
Copy Edit Raw Blame History
kamyu authored 2018-10-28 14:42 +08:00 . Update beautiful-array.cpp
// Time: O(n)
// Space: O(n)
class Solution {
public:
vector<int> beautifulArray(int N) {
vector<int> result{1};
while (result.size() < N) {
vector<int> tmp;
for (const auto& i : result) {
tmp.emplace_back(i * 2 - 1);
}
for (const auto& i : result) {
tmp.emplace_back(i * 2);
}
result = move(tmp);
}
vector<int> tmp = move(result);
for (const auto& i : tmp) {
if (i <= N) {
result.emplace_back(i);
}
}
return result;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search