- Lintcode50 Product of Array Excl
- array_product()—返回迭代计算数组键值的乘积;
- LeetCode 238. Product of Array E
- 238. Product of Array Except Sel
- Leetcode解题笔记-238. Product of Arr
- Leetcode 【238、1011】
- Maximum Product of Three Numbers
- LeetCode-628. Maximum Product of
- 628. Maximum Product of Three Nu
- 628. Maximum Product of Three Nu
【题目描述】
Given an integers array A.Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B WITHOUT divide operation.
给定一个整数数组A。定义B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], 计算B的时候请不要使用除法。
【题目链接】
http://www.lintcode.com/en/problem/product-of-array-exclude-itself/
【题目解析】
有点动态规划的思想。
首先从后往前遍历数组,用f[i]保存i到end所有元素的乘积。
然后从前往后遍历数组,对于当前位i,其值的计算公式为start~i-1的元素的乘积 * f[i]。start~i-1的乘积在i-1位置时已经可以得到。
【参考答案】
http://www.jiuzhang.com/solutions/product-of-array-exclude-itself/
网友评论