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. 《Invert》开发日志05:终止

    今天终于看了久闻大名的<独立游戏大电影>,然后我就做了一个坑爹的决定:终止“Invert”项目的开发.没错,在还没正式开工之前,我就决定停掉这个项目,而且是永久终止.做这个决定并不是因为觉 ...

  2. 【Unity3d游戏开发】Unity3D中的3D数学基础---向量

    向量是2D.3D数学研究的标准工具,在3D游戏中向量是基础.因此掌握好向量的一些基本概念以及属性和常用运算方法就显得尤为重要.在本篇博客中,马三就来和大家一起回顾和学习一下Unity3D中那些常用的3 ...

  3. python 列表转换成字符串

    用字符串的 join 方法: li = ['a', 'b', 'c', 'd'] s = ''.join(li) print(s) abcd 用字符串的占位符替换 li = ['a', 'b', 'c ...

  4. Discuz!用户注册,登陆,生成帖子功能实现

    <?php /* * Disucz!部分功能使用说明: */ /***************************************************************** ...

  5. jquery插件学习之元素顶部悬浮

    jquery插件的学习: HTML部分及应用 <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  6. poj1131-Octal Fractions(进制转换)

    一,题意: 求一个八进制小数的十进制.二,思路: 暴力数组模拟计算,注意千万不带小数做除法运算 1,对于八进制小数,转换成十进制,书写形式分析: 2,对其除法过程进行模拟: 3,输出. 三,步骤: 1 ...

  7. Google 云计算中的 GFS 体系结构

          google 公司的很多业务具有数据量巨大的特点,为此,google 公司研发了云计算技术.google 云计 算结构中的 google 文件系统是其云计算技术中的三大法宝之一.本文主要介 ...

  8. tomcatPluginV321.zip

    下载地址:http://www.eclipsetotale.com/tomcatPlugin/tomcatPluginV321.zip 或者  http://files.cnblogs.com/fil ...

  9. selenium python的使用(一)

    下面是一个爬取知网数据的例子,使用selenium 用python爬取数据 1.创建对象,打开指定地址,在休眠的20秒内输入搜索项 driver= webdriver.Chrome() driver. ...

  10. Alamofire 的使用

    最近,AFNetworking 的作者Mattt Thompson提交了一个新的类似于 AFNetworking 的网络 基础库,并且是专门使用最新的 Swift 语言来编写的,名为:Alamofir ...