剑指offer-构建乘积数组
来源:互联网 发布:软件项目范围管理 编辑:程序博客网 时间:2024/06/05 10:34
题目描述
给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。不能使用除法。
数组B[]存放A[i]之前各值的乘积,数组C[i]存放A[i]之后各值的乘积,两个相乘即可。
import java.util.ArrayList;public class Solution { public int[] multiply(int[] A) {int[] B=new int[A.length];int[] C=new int[A.length];B[0]=1;C[A.length-1]=1;for(int i=0;i<A.length-1;i++){B[i+1]=B[i]*A[i];}for(int i=A.length-1;i>0;i--){C[i-1]=C[i]*A[i];}for(int i=0;i<A.length;i++){B[i]=B[i]*C[i];}return B; }}
0 0
- 剑指offer--构建乘积数组
- 《剑指offer》构建乘积数组
- 剑指offer-构建乘积数组
- 剑指offer:构建乘积数组
- 剑指offer:构建乘积数组
- 剑指offer:构建乘积数组
- [剑指offer]构建乘积数组
- 剑指offer|构建乘积数组
- 《剑指offer》-构建乘积数组
- 剑指offer 构建乘积数组
- 构建乘积数组--剑指Offer
- 【剑指offer】构建乘积数组
- 《剑指offer》构建乘积数组
- 剑指offer-构建乘积数组
- 剑指offer--构建乘积数组
- 构建乘积数组 剑指offer
- 剑指offer-构建乘积数组
- 剑指offer:构建乘积数组
- rabbitmq
- 面向对象特性-多态
- C++ decltype类型说明符
- C语言中a=b=c,a=b==c,a==(b=c),a==(b==c)的简单分析
- Building RESTful APIs with Tornado
- 剑指offer-构建乘积数组
- java位运算
- 深入理解iOS开发中的BitCode功能
- Soju uvalive5845
- CodeForces P. Area of a Star【计算几何】
- HTML中的css和div,和table的用法
- HDU 2156 分数矩阵 (水题)
- Android学习之 错误信息显示
- leetcode Reverse Nodes in k-Group