Skip to content

Commit

Permalink
Update 238.product-of-array-except-self.md
Browse files Browse the repository at this point in the history
  • Loading branch information
azl397985856 authored Sep 30, 2019
1 parent 5501460 commit ba83b3a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion problems/238.product-of-array-except-self.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Could you solve it with constant space complexity? (The output array does not co
## 思路

这道题的意思是给定一个数组,返回一个新的数组,这个数组每一项都是其他项的乘积。
符合直觉的思路是两层循环,时间复杂度是O(n),但是题目要求`Please solve it without division and in O(n)`
符合直觉的思路是两层循环,时间复杂度是O(n^2),但是题目要求`Please solve it without division and in O(n)`

因此我们需要换一种思路,由于输出的每一项都需要用到别的元素,因此一次遍历是绝对不行的。
考虑我们先进行一次遍历, 然后维护一个数组,第i项代表前i个元素(不包括i)的乘积。
Expand Down

0 comments on commit ba83b3a

Please sign in to comment.