-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path456.cpp
More file actions
executable file
·27 lines (23 loc) · 930 Bytes
/
456.cpp
File metadata and controls
executable file
·27 lines (23 loc) · 930 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
class Solution {
public:
bool find132pattern(vector<int>& nums) {
vector<pair<int, int>> numsIndex;
for (int i = 0; i < nums.size(); i++)
numsIndex.push_back(make_pair(nums[i],i));
sort(numsIndex.begin(), numsIndex.end(), [](pair<int ,int> a, pair<int ,int> b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
});
int minindex = min(numsIndex[0].second, numsIndex[1].second);
int maxindex = max(numsIndex[0].second, numsIndex[1].second);
for (int i = 2; i < numsIndex.size(); i++){
if (numsIndex[i].second > minindex && numsIndex[i].second < maxindex){
return true;
}
minindex = min(minindex, numsIndex[i].second);
maxindex = max(maxindex, numsIndex[i].second);
}
return false;
}
};