-
Notifications
You must be signed in to change notification settings - Fork 0
/
200919-1.cpp
42 lines (40 loc) · 952 Bytes
/
200919-1.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
35
36
37
38
39
40
41
42
// https://leetcode-cn.com/problems/increasing-triplet-subsequence/
#include <iostream>
#include <vector>
#include <limits>
using namespace std;
class Solution {
public:
bool increasingTriplet(vector<int>& nums) {
if (nums.size() < 3) return false;
int a = numeric_limits<int>::max(); // record min
int b = numeric_limits<int>::max(); // record min with previous small
for (auto e : nums) {
if (e < a) a = e;
if (e > a && e < b) b = e;
if (e > b) return true;
}
return false;
}
};
int main()
{
Solution s;
{
vector<int> nums = {1,2,3,4,5};
cout << s.increasingTriplet(nums) << endl; // answer: true
}
{
vector<int> nums = {5,4,3,2,1};
cout << s.increasingTriplet(nums) << endl; // answer: false
}
{
vector<int> nums = {1,5,4,3,2};
cout << s.increasingTriplet(nums) << endl; // answer: false
}
{
vector<int> nums = {5,3,4,1,2};
cout << s.increasingTriplet(nums) << endl; // answer: false
}
return 0;
}