leetcode 238 Product of Array Except Self

来源:互联网 发布:php o2o系统 编辑:程序博客网 时间:2024/06/03 18:35

题目Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

求一个数组中除了某个元素本身的其他元素之积,,最终输出所有这样积的数组


要求:不能使用除法,时间复杂福为O(n)


思路:对于数组中的某一个元素,如果我们知道其前面所有数字的乘积,同时也知道后面所有的数乘积,那么二者相乘就是我们要的结果。


代码AC:




0 0