LeetCode: Product of Array Except Self
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的更多相关文章
- [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 ...
- LeetCode——Product of Array Except Self
Description: Given an array of n integers where n > 1, nums, return an array output such that out ...
- 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 ...
- 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 ...
- LeetCode Product of Array Except Self (除自身外序列之积)
题意:给一个序列nums,要求返回一个序列ans,两序列元素个数相同,ans第i个元素就是除了nums[i]之外所有的数相乘之积. 思路:时间O(n),额外空间O(0). 第一次扫一遍,处理nums[ ...
- LeetCode OJ 238. Product of Array Except Self 解题报告
题目链接:https://leetcode.com/problems/product-of-array-except-self/ 238. Product of Array Except Se ...
- LeetCode 238. 除自身以外数组的乘积(Product of Array Except Self)
238. 除自身以外数组的乘积 238. Product of Array Except Self 题目描述 LeetCode LeetCode238. Product of Array Except ...
- 【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 ...
- 【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 ...
随机推荐
- 2015 ACM Syrian Collegiate Programming Contest
A. My Friend of Misery 计算出答案的上下界即可. 时间复杂度$O(n)$. #include<bits/stdc++.h> using namespace std; ...
- JS:XML
一 IE中的XML //1.创建XMLDOM对象 //创建XMLDOM对象 var xmlDom = new ActiveXObject("MSXML2.DOMDocument.6.0&qu ...
- 畅通工程——D
D. 畅通工程 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的 ...
- 2016huasacm暑假集训训练四 DP_B
题目链接:http://acm.hust.edu.cn/vjudge/contest/125308#problem/M 题意:有N件物品和一个容量为V的背包.第i件物品的费用是体积c[i],价值是w[ ...
- DOS 命令For精解示例
最基本形态: 在cmd 窗口中:for %I in (command1) do command2 在批处理文件中:for %%I in (command1) do command2 在批处理中,FOR ...
- 跳转到下一个activity
/* * 第一个跳转代码 */ button.setOnClickListener(new OnClickListener() { @Override public void onClick(View ...
- Thinkphp框架
MVC思想: 1. 简单来说, M 即模型, m是Model的第一个字母,它用于管理程序的数据,因此它也是连接我们的PHP程序和数据库的功能.通常在模型类这一块,框架通常会使用ORM(对象关系映射). ...
- Thinkphp 1.验证规则 2.静态定义 3.动态验证
一.验证规则 数据验证可以对表单中的字段进行非法的验证操作.一般提供了两种验证方式: 静态定 义($_validate 属性)和动态验证(validate()方法). //验证规则 array( ar ...
- 怎么搭建DC+SCCM 域环境(一)
需要的软件: 1. SCCM 2012 SP1 2. SQL Server 2012 3. System ISO 4. ADK 环境搭建顺序: 1. 安装DC和SCCM 机器,并配置需要的IP.DNS ...
- 浅谈MySQL数据类型
MySQL 数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 一.数值类型 MySQL支持所有标 ...