剑指offer—构建乘积数组
来源:互联网 发布:服务器坏了 raid 数据 编辑:程序博客网 时间:2024/06/05 03:32
题目描述
给定一个数组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]。不能使用除法。
import java.util.ArrayList;public class Solution { public int[] multiply(int[] A) { int length = A.length; if(A==null || length<=0) return null; int[] B = new int[length]; B[0] = 1; for(int i=1; i<length; i++){ B[i] = A[i-1]*B[i-1]; } int tmp = 1; for(int i=length-2; i>=0; i--){ tmp = tmp*A[i+1]; B[i] *= tmp; } return B; }}
整个过程就是先求图中的下三角作为数组B的值,在求上三角的值乘上之前B的值,得到最终数组B的值
阅读全文
0 0
- 《剑指offer》——构建乘积数组
- 《剑指offer》——构建乘积数组
- 剑指offer——构建乘积数组
- 剑指offer——构建乘积数组
- 剑指offer—构建乘积数组
- 剑指offer—构建乘积数组
- 剑指offer--构建乘积数组
- 《剑指offer》构建乘积数组
- 剑指offer-构建乘积数组
- 剑指offer:构建乘积数组
- 剑指offer:构建乘积数组
- 剑指offer:构建乘积数组
- [剑指offer]构建乘积数组
- 剑指offer|构建乘积数组
- 《剑指offer》-构建乘积数组
- 剑指offer 构建乘积数组
- 构建乘积数组--剑指Offer
- 【剑指offer】构建乘积数组
- HDU-6249-Alice’s Stamps
- RevitAPI之创建文字和注释【比目鱼原创】
- hdu 5510 KMP+暴力
- [DP] TopCoder SRM548 Div1 450. KingdomAndDice
- 微信公众号插入地图及地图搜索资源的前端处理(坐标系转码,自动定位等业务实现)
- 剑指offer—构建乘积数组
- 服务器端的应用及服务,监控管理
- 关于dp和记忆化搜索
- JDK1.8的新特性之Lambda表达式的应用
- 论文笔记【Local-DPP: An improved DNA-binding protein prediction method by exploring local evolutionary】
- jzoj5498 【清华集训2017模拟12.10】大佬的难题 巧妙容斥
- JAVA---抽象与接口
- 利用colinux制作tinycolinx,在ecs上打造server farm和vps iaas环境代替docker
- 项目中常用的19条MySQL优化