mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 18:23:52 +00:00
Update 66. 构建乘积数组.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+5
-5
@@ -2,7 +2,7 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[NowCoder](https://www.nowcoder.com/practice/94a4d381a68b47b7a8bed86f2975db46?tpId=13&tqId=11204&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
|
||||
[Leetcode](https://leetcode.cn/problems/gou-jian-cheng-ji-shu-zu-lcof/)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
## 解题思路
|
||||
|
||||
```java
|
||||
public int[] multiply(int[] A) {
|
||||
int n = A.length;
|
||||
public int[] statisticalResult(int[] arrayA) {
|
||||
int n = arrayA.length;
|
||||
int[] B = new int[n];
|
||||
for (int i = 0, product = 1; i < n; product *= A[i], i++) /* 从左往右累乘 */
|
||||
for (int i = 0, product = 1; i < n; product *= arrayA[i], i++) /* 从左往右累乘 */
|
||||
B[i] = product;
|
||||
for (int i = n - 1, product = 1; i >= 0; product *= A[i], i--) /* 从右往左累乘 */
|
||||
for (int i = n - 1, product = 1; i >= 0; product *= arrayA[i], i--) /* 从右往左累乘 */
|
||||
B[i] *= product;
|
||||
return B;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user