*LeetCode-Product of Array Except Self
来源:互联网 发布:如何隐藏mac下方菜单 编辑:程序博客网 时间:2024/05/16 07:00
思想就是两遍 第一遍把这个数左边的乘积乘好 第二遍从右边开始,把这个数右边的乘上来
public class Solution { public int[] productExceptSelf(int[] nums) { int [] res = new int [nums.length]; res [0] = 1; for ( int i = 1; i < nums.length; i ++ ){ res[i] = nums[ i -1 ] * res[ i -1 ]; } int right = 1; for ( int i = nums.length -1; i >= 0; i --) { res[ i ] *= right; right *= nums[ i ]; } return res; }}
0 0
- [leetcode][array] Product of Array Except Self
- 【LeetCode】237 Product of Array Except Self
- #leetcode#Product of Array Except Self
- leetcode 238: Product of Array Except Self
- [leetcode] 238.Product of Array Except Self
- [leetcode] Product of Array Except Self
- LeetCode Product of Array Except Self
- leetCode(43):Product of Array Except Self
- LeetCode Product of Array Except Self
- 【leetcode】Product of Array Except Self
- 【leetcode】Product of Array Except Self
- leetcode: Product of Array Except Self
- [leetcode] Product of Array Except Self
- [LeetCode] Product of Array Except Self
- Leetcode: Product of Array Except Self
- LeetCode 238: Product of Array Except Self
- LeetCode-Product of Array Except Self
- Leetcode #238 Product of Array Except Self
- 最长公共子序列(LCS)问题
- *LeetCode-Populating Next Right Pointers in Each Node
- eetCode] Basic Calculator & Basic Calculator II Basic Calculator
- Perfect Squares
- Count Complete Tree Nodes
- *LeetCode-Product of Array Except Self
- Contains Duplicate III
- LeetCode Distinct Subsequences
- Contains Duplicate III
- 一起来算圆周率
- *LeetCode-Integer to Roman
- HBase 1.1.2安装(伪分布式)
- LeetCode Interleaving String
- 中国天气网 天气预报API 国家气象局 根据城市名称抓取城市ID,XML格式、JSON格式、图片代码