leetcode--Product of Array Except Self
来源:互联网 发布:php查找字符串位置 编辑:程序博客网 时间:2024/06/07 00:37
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]
.
Follow up:
Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)
题意:给定一个数组,返回一个结果数组。要求结果数组中的每个元素,等于原数组中的该位置以外的元素的乘积。
例如{1,2,3,4},1位置上的,为2*3*4,那么结果数组的0位就是24
要求不能使用除法,并且时间复杂度为O(n)
你能在常数空间实现吗?output[]数组的空间不计算在内
分类:数组
解法1:解法有点巧妙。使用一个数组,保存元素组某位置,例如i,保存i前的所以元素的乘积
另外一个数组,保存i后所有元素的乘积
最后这两个数组相乘
优化一下代码:
原文链接http://blog.csdn.net/crazy__chen/article/details/47906303
阅读全文
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
- 第一个博客
- DDD、CQRS、Event Sourcing
- 测试字节序
- 自定义控件三部曲之绘图篇(十)——Paint之setXfermode(一)
- 服务端常用的架构
- leetcode--Product of Array Except Self
- Android广播的超时机制
- bseg---faglflexta
- poj3904 容斥原理或莫比乌斯反演
- Git内网服务搭建全过程
- SpringMVC自定义错误页面
- es配置中防止脑裂的配置
- Ubuntu网络配置
- 帮助方法 Array