Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

Solve it without division and in O(n).

For example, given [1,2,3,4], return [24,12,8,6].

public class Solution {  //左边的数乘积乘以右边的数乘积。
public int[] productExceptSelf(int[] nums) {
int[] res=new int[nums.length];
res[0]=1;
int acc=1;
for(int i=1;i<nums.length;i++){
res[i]=res[i-1]*nums[i-1];
}
for(int i=nums.length-1;i>=0;i--){
res[i]*=acc;
acc*=nums[i];
}
return res;
}
}

(Skill)238. Product of Array Except Self的更多相关文章

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

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

  2. 238. Product of Array Except Self(对O(n)和递归又有了新的理解)

    238. Product of Array Except Self     Total Accepted: 41565 Total Submissions: 97898 Difficulty: Med ...

  3. LN : leetcode 238 Product of Array Except Self

    lc 238 Product of Array Except Self 238 Product of Array Except Self Given an array of n integers wh ...

  4. leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、407. Trapping Rain Water II

    11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情 ...

  5. 【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 ...

  6. leetcode:238. Product of Array Except Self(Java)解答

    转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Product of Array Except Self Given an array of n integers where n > ...

  7. 【刷题-LeetCode】238. Product of Array Except Self

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

  8. [LeetCode] 238. 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 ...

  9. 238. 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 ...

随机推荐

  1. Spring配置文件详解 - applicationContext.xml文件路径

    spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...

  2. STM3210x建工程库函数版本

    1.首先下载一个固件库,我下载的是stm32f10x_stdperiph_lib 3.5V版的 2.新建一个文件夹,可命名为"STM32建工程库函数版本" 3.在"STM ...

  3. HTML5 input placeholder 颜色修改示例

    Chrome支持input=[type=text]占位文本属性,但下列CSS样式却不起作用: CSS 复制代码 代码如下: input[placeholder], [placeholder], *[p ...

  4. jstl 标签库的使用

    JSTL 核心标签库 使用   JSTL 核心标签库标签共有13个,功能上分为4类: 1.表达式控制标签:out.set.remove.catch 2.流程控制标签:if.choose.when.ot ...

  5. Dos学习笔记(3)attrib命令

    今天和昨天一直在摸索这个命令觉得这个命令为什么改变不了文件夹的属性, 因为我试着用attrib +r /s 去修改子文件夹的时候发现没用,然后如果输入 attrib +r /d 又提示说/d需要和/s ...

  6. 汇编语言进阶和Makefile进阶---第二天

    摘要: 原创博文:转载请标明出处:http://www.cnblogs.com/zxouxuewei 首先加载启动代码: ; hello-os ; TAB=4 ORG 0x7c00 ; 指明程序装载地 ...

  7. 启动odoo-10.0成功,但是访问时出错

    启动odoo-10.0显示成功 2017-01-05 06:49:48,211 532 INFO ? odoo: Odoo version 10.02017-01-05 06:49:48,211 53 ...

  8. CentOS 7 安装 WordPress,PHP,Nginx,MySQL(MariaDB),FTP

    主要资料参考:https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-st ...

  9. VC++常用函数

    // 获取文件运行路径 void GetAppFilePath(const CString& strProjectName) { TCHAR szFileName[MAX_PATH]; HMO ...

  10. 【转载】浅谈游戏开发之2D手游工具

    浅谈游戏开发之2D手游工具 来源:http://www.gameres.com/459713.html 游戏程序 平台类型: iOS Android  程序设计: 其它  编程语言:   引擎/SDK ...