面试题66. 构建乘积数组
2021-01-25 16:14
标签:png for 面试 public color cto struct ret idt 题目: 解答:
面试题66. 构建乘积数组 标签:png for 面试 public color cto struct ret idt 原文地址:https://www.cnblogs.com/ocpc/p/12859896.html 1 class Solution {
2 public:
3 vectorint> constructArr(vectorint>& a) 、
4 {
5 int n = a.size();
6 vectorint> ret(n, 1);
7
8 int left = 1;
9 for (int i = 0; i )
10 {
11 ret[i] = left;
12 left = left * a[i];
13 }
14
15 int right = 1;
16 for (int i = n-1; i >= 0; i --)
17 {
18 ret[i] *= right;
19 right *= a[i];
20 }
21 return ret;
22 }
23 };