Skip to content

Commit 378e773

Browse files
committed
Add 238 note.
1 parent 037c6fb commit 378e773

File tree

1 file changed

+15
-0
lines changed
  • solutions/238.Product_of_Array_Except_Self

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 238. Product of Array Except Self (Medium)
2+
3+
### **链接**
4+
题目:https://leetcode.com/problems/product-of-array-except-self/
5+
代码(github):https://github.com/illuz/leetcode
6+
7+
### **题意**
8+
把一个数组中的每个数 替换为 这个数组中除了它自身的其它数的积。
9+
10+
### **分析**
11+
12+
1. 最暴力的是直接在每个位置计算其它数的积,时间复杂度 O(n*n)。
13+
2. 先算出所有的数的积,再去用除法求出解,要注意数组里可能会有 0,一个 0 和多个 0 的情况是不一样的。空间复杂度是 O(1),时间是 O(n)。
14+
3. 其实就是算每个位置上左边的数和右边的数的积,所以可以开数组预处理出每个位置左右两边的积,然后再相乘就行了。实际做的时候只要用一个数组记录一边就行了,另一边可以一边算一边得出解来。
15+

0 commit comments

Comments
 (0)