-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path132Pattern3.cpp
More file actions
43 lines (33 loc) · 750 Bytes
/
132Pattern3.cpp
File metadata and controls
43 lines (33 loc) · 750 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Solution {
public:
bool find132pattern(vector<int>& nums) {
int n = nums.size();
int i = 0;
while(i < n) {
while(i < n - 1 && nums[i] >= nums[i + 1]) i++;
int j = i + 1;
while(j < n - 1 && nums[j] <= nums[j + 1]) j++;
for(int k = j + 1; k < n; k++)
if(nums[k] > nums[i] && nums[k] < nums[j]) return true;
i = j + 1;
}
return false;
}
};
int main() {
int n;
cin>>n;
vector<int> nums;
for(int i = 0; i < n; i++) {
int num;
cin>>num;
nums.push_back(num);
}
Solution *solution = new Solution();
solution->find132pattern(nums) ? cout<<"true" : cout<<"false";
return 0;
}