Interview:ProductExceptSelf
❓ 问题
给你一个整数数组 nums,你要生成一个新的数组 res,满足:
res[i] = 除了 nums[i] 之外,数组里所有其他数的乘积。
限制条件:
- 不能用除法
- 时间复杂度要 O(n)
🧠 思路总结
对任意一个位置i:
当前位置的结果 = 左边所有数的乘积 ✖️ 右边所有数的乘积
使用前缀 & 后缀法
✅ 代码(Java)
1 | |
Interview:ProductExceptSelf
https://powersixxx.github.io/leetcode-blog/2026/01/10/Interview-ProductExceptSelf/