Skip to content

Commit

Permalink
Time: 7 ms (57.25%), Space: 13.8 MB (63.54%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Aug 23, 2023
1 parent a5d6684 commit c6a87b0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 0152-maximum-product-subarray/0152-maximum-product-subarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int maxProduct(vector<int>& nums) {
int pre=1;
int pos=1;
int ans=INT_MIN;

for(int i=0;i<nums.size();i++)
{
if(pre==0)pre=1;
if(pos==0)pos=1;
pre=pre*nums[i];
pos=pos*nums[nums.size()-i-1];
ans=max(ans,max(pre,pos));
}
return ans;

}
};

0 comments on commit c6a87b0

Please sign in to comment.