锅炉信息网 > 锅炉知识 > 锅炉资讯

932. Beautiful Array

发布时间:

// LeetCode 2020 medium #863nn// 932. Beautiful Arrayn// https://leetcode.com/problems/beautiful-array/nn// Runtime: 0 m

// LeetCode 2020 medium #863nn// 932. Beautiful Arrayn// https://leetcode.com/problems/beautiful-array/nn// Runtime: 0 ms, faster than 100.00% of C++ online submissions for Beautiful Array.n// Memory Usage: 8.4 MB, less than 5.82% of C++ online submissions for Beautiful Array.nnclass Solution {n unordered_map<int, vector<int>> m;n npublic:n vector<int> beautifulArray(int N) {n if (N == 1) return {1};n if (m.count(N)) return m[N];n n vector<int> arr(N);n int j = 0;n auto odd = beautifulArray((N + 1) / 2);n for (int i = 0; i < odd.size(); ++i)n arr[j++] = odd[i] * 2 - 1;n auto even = beautifulArray(N - (N + 1) / 2);n for (int i = 0; i < even.size(); ++i)n arr[j++] = even[i] * 2;n m[N] = arr;n return arr;n }n};nn// Runtime: 16 ms, faster than 23.97% of C++ online submissions for Beautiful Array.n// Memory Usage: 16.2 MB, less than 5.82% of C++ online submissions for Beautiful Array.nnclass Solution {npublic:n vector<int> beautifulArray(int N) {n if (N == 1) return {1};n n vector<int> arr(N);n int j = 0;n auto odd = beautifulArray((N + 1) / 2);n for (int i = 0; i < odd.size(); ++i)n arr[j++] = odd[i] * 2 - 1;n auto even = beautifulArray(N - (N + 1) / 2);n for (int i = 0; i < even.size(); ++i)n arr[j++] = even[i] * 2;n return arr;n }n};n

上一篇:壁挂炉品牌推荐

下一篇:ADVANTECH

精选推荐

  • 如何正确选择白板供应商
    如何正确选择白板供应商

    目前在无锡想采购一块白板不管是实体店铺,还是网络平台都有很多选择,想要到专业的无锡白板公司采购还需要掌握一定的方式技巧。现

  • 柴油发电机组供应商
    柴油发电机组供应商

      t 扬州华东动力机械有限公司,位于江苏省扬州市江都区仙城工业园,是专业从事发电机、柴油及燃气发电机组研发、制造、销售、服务于

  • 高温辐射炉
    高温辐射炉

    5.2.2高温辐射炉5.2.2.1温度控制★(1)样品温度范围:常温~1400℃。★(2)均温区:长度不小于80mm。★(3)中心区:长度不小于10mm。(4)温度梯度(均

  • 高压锅在什么情况下会爆炸?
    高压锅在什么情况下会爆炸?

    近日,多地发生高压锅爆炸事故,给不少家庭带来了伤害和财产损失。那么,什么情况下会导致高压锅爆炸呢?首先,当高压锅内部压力过高时,如果

0