当前位置: 代码迷 >> 综合 >> 238 https://leetcode-cn.com/problems/product-of-array-except-self/
  详细解决方案

238 https://leetcode-cn.com/problems/product-of-array-except-self/

热度:78   发布时间:2023-10-13 02:37:50.0
class Solution {
    
public:vector<int> productExceptSelf(vector<int>& nums) {
    int n = nums.size();vector<int> output(n,1);//初始化一个全为1的向量for(int i=1;i<n;i++){
    output[i] = output[i-1]*nums[i-1];}int end=1;for(int i=n-1;i>=0;i--){
    output[i]*=end;end *=nums[i];}return output;}
};
  相关解决方案