leetcode刷题,总结,记录,备忘238
来源:互联网 发布:淘宝发布宝贝怎么预览 编辑:程序博客网 时间:2024/06/06 07:39
leetcode238
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]
.
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) { vector<int>temp(nums.size(), 1); for (int i = 1; i < nums.size(); ++i) { temp[i] = temp[i-1] * nums[i-1]; } int n = 1; for (int i = nums.size()-1; i >= 0; --i) { temp[i] *= n; n *= nums[i]; } return temp; }};
0 0
- leetcode刷题,总结,记录,备忘238
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- UVALive 4253 Archery(二分+atan2应用)
- C/C++/IOS/Android/MFC/python等软件定制服务,有人需要吗?
- POJ 1293 Duty Free Shop
- 主机之间建立ssh互信
- 堆排序
- leetcode刷题,总结,记录,备忘238
- hdoj1000and1089(a+b)
- day03
- XML文件操作--创建
- bean的别名使用的注意事项
- c_函数指针
- Android中的命名规范
- LightOJ1074 SPFA判负环
- static简介