leetcode 238. Product of Array Except Self (乱搞)

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].

Solve it without division and in O(n).

For example, given [1,2,3,4], return [24,12,8,6].

Follow up:
Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)

 先来个O(n)空间的无脑解法。。。一个前缀积一个后缀积就好了。。。

常数空间的做法。。。想了半天没有想法。。。

看了solution…发现就是借用res数组搞事情。。。。每个位置的答案扫完两遍得到。。。

感觉。。。非常的。。。无聊啊。。。。真心没意思吧,还以为是什么巧妙的做法呢。。。

 

作者: CrazyKK

ex-ACMer@hust,researcher@sensetime

说点什么

您将是第一位评论人!

提醒
wpDiscuz