-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
34 lines (33 loc) · 841 Bytes
/
main.cpp
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
29
30
31
32
33
34
class Solution {
public:
bool increasingTriplet(vector<int>& nums) {
vector<int> triplet;
for (int v : nums) {
auto it = lower_bound(triplet.begin(), triplet.end(), v);
if (it == triplet.end()) {
triplet.push_back(v);
if (triplet.size() == 3) return true;
continue;
}
*it = v;
}
return false;
}
};
class Solution {
public:
bool increasingTriplet(vector<int>& nums) {
int a = numeric_limits<int>::max();
int b = numeric_limits<int>::max();
for (int v : nums) {
if (v <= a) {
a = v;
} else if (v <= b) {
b = v;
} else {
return true;
}
}
return false;
}
};