leetcode 除自身以外数组的乘积 中等
作者:互联网
直接看代码,比文字解释清楚
class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { vector<int> res(nums.size(), 1); int lef = 1, rig = 1; for(int i = 0, j = nums.size() - 1; i < nums.size(); ++ i, --j) { res[i] *= lef; res[j] *= rig; lef *= nums[i]; rig *= nums[j]; } return res; } };
标签:乘积,lef,nums,res,vector,数组,rig,leetcode,size 来源: https://www.cnblogs.com/rookie-acmer/p/15086592.html