class Solution {
public:
vector
<int> constructArr(vector
<int>& a
) {
int n
= a
.size();
vector
<int>l(n
, 1);
vector
<int>r(n
, 1);
for (int i
= 1; i
< n
; i
++) {
l
[i
] = l
[i
- 1] * a
[i
- 1];
r
[n
- 1 - i
] = r
[n
- i
] * a
[n
- i
];
}
auto ans
= a
;
for (int i
= 0; i
< n
; i
++)
ans
[i
] = l
[i
] * r
[i
];
return ans
;
}
};
转载请注明原文地址: https://lol.8miu.com/read-22237.html