【nc】 Arrays&Hashing 6/9 product-of-array-except-self 除自身以外数组的乘积 238

 ===

思路:

时间复杂度为O n

1. res数组表示结果值

2. 首先设置prefix和postfix为1

3. 第一次正向遍历的时候res[i]的值为prefix,prefix是prefix * nums[i]

4. 第二次反向遍历的时候res[i]的值是postfix * res[i],postfix是postfix * nums[i]

最终返回res

 

posted @ 2023-06-24 03:37  hh9515  阅读(12)  评论(0)    收藏  举报