Dynamic Programming

 public class Solution {
public int[] productExceptSelf(int[] nums) {
int[] ans = new int[nums.length];
for (int i = 0; i < ans.length; i++) ans[i] = 1;
int product = 1;
for (int i = 1; i < ans.length; i++) {
product *= nums[i-1];
ans[i] *= product;
}
product = 1;
for (int i = ans.length-2; i >= 0; i--) {
product *= nums[i+1];
ans[i] *= product;
}
return ans;
}
}

LeetCode: Product of Array Except Self的更多相关文章

  1. [LeetCode] Product of Array Except Self 除本身之外的数组之积

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  2. LeetCode——Product of Array Except Self

    Description: Given an array of n integers where n > 1, nums, return an array output such that out ...

  3. 238. [LeetCode] Product of Array Except Self

    Given an array nums of n integers where n > 1,  return an array output such that output[i] is equ ...

  4. LeetCode -- Product of Array Except Self My Submissions Question

    Question: Given an array of n integers where n > 1, nums, return an array output such that output ...

  5. LeetCode Product of Array Except Self (除自身外序列之积)

    题意:给一个序列nums,要求返回一个序列ans,两序列元素个数相同,ans第i个元素就是除了nums[i]之外所有的数相乘之积. 思路:时间O(n),额外空间O(0). 第一次扫一遍,处理nums[ ...

  6. LeetCode OJ 238. Product of Array Except Self 解题报告

        题目链接:https://leetcode.com/problems/product-of-array-except-self/ 238. Product of Array Except Se ...

  7. LeetCode 238. 除自身以外数组的乘积(Product of Array Except Self)

    238. 除自身以外数组的乘积 238. Product of Array Except Self 题目描述 LeetCode LeetCode238. Product of Array Except ...

  8. 【LeetCode】Product of Array Except Self

    Product of Array Except Self Given an array of n integers where n > 1, nums, return an array outp ...

  9. 【LeetCode】238. Product of Array Except Self

    Product of Array Except Self Given an array of n integers where n > 1, nums, return an array outp ...

随机推荐

  1. Tomcat配置HTTPS方式(单向)

    简要记录主要步骤备忘 1.进入到jdk下的bin目录 2.输入如下指令 keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/tomcat ...

  2. 【Oracle】oracle10g以后利用q-quote特性简化包含单引号后双引号的字符串写法

    The Q-quote delimiter can be any single- or multibyte character except space, tab, and return. If th ...

  3. Qt里获取目录的一个另类方法

    如果有一个文件的全路径文件名, 想获取它的路径的话, qt里我没找到比较好的办法, 都是cleanPath后, 再用QString的find, left这种函数来处理. 今天又在搞这种问题的时候, 看 ...

  4. oracle在cmd中启动数据库实例

    在cmd中启动数据库实例: sqlplus /nolog 回车, conn as sysdba;回车,startup;然后回车

  5. hdu 4899 Hero meet devil

    传送阵:http://acm.hdu.edu.cn/showproblem.php?pid=4899 题目大意:给定一个DNA序列,求有多少长度为m的序列与该序列的最长公共子序列长度为0,1...|S ...

  6. C# 方法返回值的个数

    方法返回值类型总的来说分为值类型,引用类型,Void 有些方法显示的标出返回值 public int Add(int a,int b) { return a+b; } 有些方法隐式的返回返回值,我们可 ...

  7. js 小知识

    在iframe 页面获取父级页面的 html var obj = window.parent.document.getElementById('modaliframe'); 解决Jquery 的在一个 ...

  8. MySQL 主从配置

    mysql主从复制指两个服务器之间数据库的同步,当主服务器的数据进行了变更,从服务器也会自动更新,其过程是通过bin-log日志实现的,本质是binlog日志的传输. mysql主从分两个角色 1.主 ...

  9. Java中Map常用方法总结以及遍历方式的汇总

    一.整理: 看到array,就要想到角标. 看到link,就要想到first,last. 看到hash,就要想到hashCode,equals. 看到tree,就要想到两个接口.Comparable, ...

  10. 通过命令创建vue项目

    环境要求:  安装有 Node.js. vue. vue-cli . 创建项目: vue init webpack projectName 进入项目,下载依赖: npm install 或者 cnpm ...