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. linux 查看Java 进程的内存使用情况

    top -b -n 1 | grep java| awk '{print "PID:"$1",mem:"$6",CPU percent:"$ ...

  2. requerjs 合并 优化配置

    /* * This is an example build file that demonstrates how to use the build system for * require.js. * ...

  3. java的poi技术读取Excel[2003-2007,2010]

    这篇blog主要是讲述java中poi读取excel,而excel的版本包括:2003-2007和2010两个版本, 即excel的后缀名为:xls和xlsx. 读取excel和MySQL相关: ja ...

  4. 文件编码、charset、sublime编辑器支持GBK等问题

    问题一:如何让sublime3支持GBK 首先打开package control ,然后键入install package进入,搜索ConvertToUTF8安装成功后 打开要查看的GBK文件,点击菜 ...

  5. quartz与spring进行集成

    上一篇将了quartz框架的使用,spring同样也提供了对quartz的集成.这次就尝试一下在spring中集成quartz. 要在spring中使用job,Trigger和Scheduler,就要 ...

  6. [LintCode] Majority Number 求众数

    Given an array of integers, the majority number is the number that occurs more than half of the size ...

  7. struts2上传图片的全过程

    struts2上传图片的过程 1.写一个上传的jsp页面upload_image.jsp,内容如下:<body><center>    <font color=" ...

  8. c语言文法简化版文法

    <源程序>→<外部声明>|<外部声明><函数体> <外部申明>→<头文件><函数声明>|其他声明 <函数体&g ...

  9. System.Data.SqlClient.SqlException: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - 定位指定的服务器/实例时出错)

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. ...

  10. Spring注解@Resource和@Autowired区别对比

    转载:http://www.cnblogs.com/think-in-java/p/5474740.html @Resource和@Autowired都是做bean的注入时使用,其实@Resource ...