注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 sing1ee 于 2013-3-16 16:56 编辑
Given an array of numbers, nums, return an array of numbers products, where products is the product of all nums[j], j != i. Input : [1, 2, 3, 4, 5]Output: [(2*3*4*5), (1*3*4*5), (1*2*4*5), (1*2*3*5), (1*2*3*4)] = [120, 60, 40, 30, 24]You must do this in O(N) without using division.
We can solve this question by O(n) time and O(n) space, or O(n) time and O(1)space by traversing the array two times. Or We can sovle in a recursive method.
perl, but easy to understand.
|