leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0932.cpp (398B)


      1 class Solution {
      2   public:
      3     vector<int> beautifulArray(int n) {
      4         vector<int> res = {1};
      5         while (res.size() < n) {
      6             vector<int> tmp;
      7             for (int i : res)
      8                 if (i * 2 - 1 <= n) tmp.push_back(i * 2 - 1);
      9             for (int i : res)
     10                 if (i * 2 <= n) tmp.push_back(i * 2);
     11             res = tmp;
     12         }
     13         return res;
     14     }
     15 };