随笔 - 165,  文章 - 0,  评论 - 4,  阅读 - 18023

题目:

class Solution {
public:
    vector<int> constructArr(vector<int>& a) {
        int len = a.size();
        if(len==0) return {};
        vector<int> b(len, 1);
        for(int i=1;i<len;i++){      //先计算b[i]下三角的乘积。由图可看出b[1]乘的是a[0]
            b[i]=b[i-1]*a[i-1];
        }
        int tmp=1;
        for(int i=len-2;i>=0;i--){      //再计算b[i]上三角的乘积,乘积用tmp存储和迭代。由图可看出b[3]乘的是a[4]
            tmp*=a[i+1];
            b[i]*=tmp;
        }
        return b;
    }
};

作者:Krahets
链接:https://leetcode.cn/problems/gou-jian-cheng-ji-shu-zu-lcof/solutions/208840/mian-shi-ti-66-gou-jian-cheng-ji-shu-zu-biao-ge-fe/
来源:力扣(LeetCode)

posted on   孜孜不倦fly  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示