(Skill)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 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的更多相关文章
- LeetCode OJ 238. Product of Array Except Self 解题报告
题目链接:https://leetcode.com/problems/product-of-array-except-self/ 238. Product of Array Except Se ...
- 238. Product of Array Except Self(对O(n)和递归又有了新的理解)
238. Product of Array Except Self Total Accepted: 41565 Total Submissions: 97898 Difficulty: Med ...
- 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 ...
- 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 用双指针向中间滑动,较小的高度就作为当前情 ...
- 【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 ...
- leetcode:238. Product of Array Except Self(Java)解答
转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Product of Array Except Self Given an array of n integers where n > ...
- 【刷题-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 ...
- [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 ...
- 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 ...
随机推荐
- robotframework接口测试初探1
robotframework这个框架最近很多人在使用它,大部分是和selenium结合的,大概看了下,然后发现这个做接口测试感觉也还不错,初步研究了下 环境安装: robotframework这个环境 ...
- CSS外边距margin上下元素重叠
CSS外边距margin上下元素重叠 转载:http://www.gaoyouyou.com/view/77.htm 两个或多个块级盒子的垂直相邻边界会重合.结果的边界宽度是相邻边界宽度中最大的值.如 ...
- Android之AnimationDrawable初识
Drawable animation可以加载Drawable资源实现帧动画.AnimationDrawable是实现Drawable animations的基本类. 这里用AnimationDrawa ...
- Sep14学习笔记_pipe() & fork()
第一次用博客园,昨晚编辑器一直没打开,今天打开了,把昨天的内容先补一下 关于parent和child之间的数据传输: If the parent wants to receive data from ...
- ready和onload的区别
$(document).ready()和window.onload在表面上看都是页面加载时我们就去执行一个函数或动作,但是在具体的细节上$(document) ready()和window onloa ...
- Redis和Memcache的区别
Redis和Memcache的区别 总结一: 1.数据类型 redis数据类型丰富,支持set liset等类型 memcache支持简单数据类型,需要客户端自己处理复杂对象 2.持久性 redis支 ...
- java中常见的几种Runtimeexception
转自http://blog.csdn.net/qq635785620/article/details/7781026 一般面试中java Exception(runtimeException )是必会 ...
- Pocscan搭建详解
0x01 关于Pocscan Pocscan是一款开源 Poc 调用框架,可轻松调用Pocsuite,Tangscan,Beebeeto,Knowsec老版本POC 按照官方规范编写的 Poc对目标域 ...
- php获取post参数的几种方式 RPC 规定接收取值方式 $GLOBALS['HTTP_RAW_POST_DATA'];
http://www.cnblogs.com/zhepama/p/4022606.html PHP默认识别的数据类型是application/x-www.form-urlencoded标准的数据类型. ...
- WebAPI学习点滴(一)
对于GET请求,如果方法名不是以Get开头,就必须加上[HttpGet]标签,不然无法找到该方法,如果是以Get开头则没有这个问题. 因此,推荐所有方法都确定访问方式,加上标签. [HttpGet] ...