-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathday18.cpp
More file actions
24 lines (24 loc) · 757 Bytes
/
day18.cpp
File metadata and controls
24 lines (24 loc) · 757 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
class Solution {
public:
bool increasingTriplet(vector<int>& nums) {
int a = INT_MAX , b = INT_MAX;
if(nums.size() < 3) // we need to have minimum of 3 elements.
return false;
for(int i= 0;i<nums.size();i++)
{
if(nums[i] <= a) //comparing the integers one by one with the initial MAX-defined.
{
a = nums[i];
}
else if(nums[i] <= b) //comparing the integers one by one with the initial MAX-defined if the first condition fails.
{
b = nums[i];
}
else // we don't need to store the third variable .
{
return true;
}
}
return false;
}
};