238. Product of Array Except Self
来源:互联网 发布:电梯维修需要编程吗 编辑:程序博客网 时间:2024/06/18 09:51
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.)
代码:
class Solution {public: vector<int> productExceptSelf(vector<int>& nums) { int n=nums.size(); int tmp=1; vector<int>res(n); for(int i=0;i<n;i++) { res[i]=tmp; tmp*=nums[i]; } tmp=1; for(int i=n-1;i>=0;i--) { res[i]*=tmp; tmp*=nums[i]; } return res; }};
0 0
- [leetcode] 238.Product of Array Except Self
- [LeetCode]238.Product of Array Except Self
- [leetcode] 238. Product of Array Except Self
- Leetcode 238. Product of Array Except Self
- [LeetCode]238. Product of Array Except Self
- 238. Product of Array Except Self LeetCode
- LeetCode 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- [LeetCode]238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- 238. Product of Array Except Self
- LeetCode *** 238. Product of Array Except Self
- LeetCode 238. Product of Array Except Self
- 断点续传&网络编程day2(66期第五天)
- Failing Oozie Launcher, Main class [org.apache.oozie.action.hadoop.ShellMain], exit code [1]
- 编码-京东实习笔试编程题-糖果问题-动态规划
- Oracle-10-对表中数据进行增删改查
- 关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- 238. Product of Array Except Self
- LeetCode(54)-Longest Common Prefix
- ubuntu使用下载的deb文件制作本地源
- java获取文件名的三种方法
- 百钱买百鸡问题
- Java中的原子性与并发编程总结
- CDOJ 251 导弹拦截 LIS
- iOS 关联策略 详解
- BZOJ2152 聪聪可可 点分治