-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDay-069.cpp
More file actions
28 lines (28 loc) · 778 Bytes
/
Day-069.cpp
File metadata and controls
28 lines (28 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
public:
int maximumProduct(vector<int>& nums) {
int max1 , max2 , max3;
int min1 , min2;
max1 = max2 = max3 = numeric_limits<int>::min();
min1 = min2 = numeric_limits<int>::max();
for(auto&itr:nums){
if(itr>=max1){
max3 = max2;
max2 = max1;
max1 = itr;
}else if(itr>=max2){
max3 = max2;
max2 = itr;
}else if(itr>=max3){
max3 = itr;
}
if(itr<=min1){
min2 = min1;
min1 = itr;
}else if(itr<=min2){
min2 = itr;
}
}
return std::max({max1*max2*max3 , min1*min2*max1});
}
};