Given an input array of number {1,2,3,4,5,6}, output number of array {2*3*4*5*6, 1*3*4*5*6,1*2*4*5*6,1*2*3*5*6,1*2*3*4*6,1*2*3*4*5 }. Do not use divide.
Solution:
public int[] getAllProductsExceptSelf(int[] num) { if(num == null || num.length == 1) return null; final int len = num.length; int[] result = new int[len]; int[] leftProducts = new int[len+1]; int[] rightProducts = new int[len+1]; leftProducts[0] = 1; rightProducts[len] = 1; for(int i=1; i<=len; i++) { leftProducts[i] = leftProducts[i-1] * num[i-1]; } for(int i=len-1; i>=0; i--) { rightProducts[i] = rightProducts[i+1] * num[i]; result[i] = leftProducts[i] * rightProducts[i+1]; } return result; }
Time Complexity: O(n).
相关推荐
精品软件工具--Automatically generate model files, support JSON an
Given an array of integers where all the numbers are appearing twice find the only two numbers which appears once Chapter 12. Multiply two numbers without using arithmetic operators Chapter 13. ...
It will generate code for all versions of MyBatis, and versions of iBATIS after version 2.2.0. It will introspect a database table (or many tables) and will generate artifacts that can be used to ...
Verilog-2001添加了generate循环,...1. generate语法有generate for, genreate if和generate case三种 2. generate for语句必须有genvar关键字定义for的变量 3. for 的内容必须加begin和end 4. 必须给for语段起个名字
generate_all_certs.avi
英文版On the other hand, this isn't an advanced technical treatise either. It's a book of design patterns that describes simple and elegant solutions to specific problems in object-oriented software ...
_.where(list, properties) Looks through each value in the list, returning an array of all the values that contain all of the key-value pairs listed in _.findWhere(list, properties) Looks through the ...
Generate Waveform.vi
codegenerate-1.0.4.jar
Generate an APK Set archive containing APKs for all possible devices. Extract APK(s) from the APK Set compatible with a given device. Install APK(s) from the APK Set compatible with a connected ...
IDEA通过Generate.POJOs.groovy映射数据库自动生成对应的Java实体类, 具体逻辑不详细展示,可参考:https://blog.csdn.net/weixin_40375601/article/details/106807644
AN12554 Demo Application to Generate Red/Black Blobs Using CAAM and Encrypt/Decrypt Data
codegenerate-3.6.1.jar的源码,下载了最新jd-gui工具反编译的。jeecg框架是最新的3.7,最近做二次开发需要修改自动生成代码。做jeecg二次开发的可以相互探讨交流
Describes a way to automatically generate an application build number.(35KB)
labview中找不到的generate waveform.vi Generate Waveform .VI程序 目录为activity\Generate Waveform.vi Labview8.5中的Generate Waveform VI labview 8.6中找不到generate waveform vi文件 labview中的一个自带的...
Generate code statement for hardcode
codegenerate-3.6.1.jar的源码,下载了最新jd-gui工具反编译的。jeecg框架是最新的3.7,最近做二次开发需要修改自动生成代码。做jeecg二次开发的可以相互探讨交流
jeecg-mybatis-generate 源码
Win7旗舰版,64bit,VS2005+WINCE6.0在导出SDK时失败,报错如下: “'C:/Program' Files (x86)/Microsoft Visual Studio 8/Common7/IDE>"C:/Program Files (x86)/Microsoft Platform Builder/6.00/cepb/IdeVS/GenSdk...
GenerateKey EncryptClasses Util DecryptStart 源码