(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 ...
随机推荐
- http 学习 1-1 chapter1-HTTP概述
Web浏览器.服务器和相关的Web应用程序都是通过HTTP相互通信的.HTTP是现代全球因特网中使用的公共语言. 1.1HTTP – 因特网的多媒体信使 HTTP使用的是可靠的数据传输协议,确保数据在 ...
- 不就ideas嘛,谁没有!
20160214 survey of current RDF triple storage systems survey of semantic web stack inference mechani ...
- 《Android深度探索HAL与驱动开发》第二章阅读心得
按照书中所讲的步骤,第一步先准备好搭建Android开发环境所需要的工具:JDK6或以上版本:Eclipse3.4或以上版本:ADT:CDT:Android SDK:Android NDK;交叉编译环 ...
- WebLogic口令猜解工具【Python脚本】
WebLogic 默认端口7001 可以通过如下链接访问控制台 http://10.9.1.1:7001/console/login/LoginForm.jsp 写了一个简单的猜解脚本,半成品,做个记 ...
- GetLastError返回值的含义
[0]-操作成功完成. [1]-功能错误. [2]-系统找不到指定的文件. [3]-系统找不到指定的路径. [4]-系统无法打开文件. [5]-拒绝访问. [6]-句柄无效. [7]-存储控制块被损坏 ...
- jsonp案例
<button id="btn">click</button><script type="text/javascript"> ...
- zendstuido10 配置spket插件
必备:Zend Studio.Spket Plugin.sdk.jsb3.百度 安装过程中出现了两种错误,导致最后安装spket时报错,一种是提示“The file "F:\study\to ...
- MYCAT 配置(转)
server.xml配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mycat:se ...
- OPENVPN
安装 方法1--源码安装yum -y install pam pam-devel gcc gcc-c++ lzo lzo-devel openssl openssl-devel wget autom ...
- FP-tree推荐算法
推荐算法大致分为: 基于物品和用户本身 基于关联规则 基于模型的推荐 基于物品和用户本身 基于物品和用户本身的,这种推荐引擎将每个用户和每个物品都当作独立的实体,预测每个用户对于每个物品的喜好程度,这 ...