-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path132_pattern.cpp
More file actions
29 lines (26 loc) · 769 Bytes
/
132_pattern.cpp
File metadata and controls
29 lines (26 loc) · 769 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
class Solution {
public:
bool find132pattern(vector<int>& nums) {
int fin[nums.size()];
fin[0] = nums[0];
for(int i = 1; i < nums.size(); i++){
fin[i] = min (fin[i-1],nums[i]);
}
stack<int>s;
for(int i = nums.size()-1; i>=0; i--){
if(fin[i] < nums[i]){
while(!s.empty() &&( s.top()<=fin[i] )){
s.pop();
}
// if(s.empty() ){
// return false;
// }
if(!s.empty() && s.top() <nums[i]){
return true;
}
s.push(nums[i]);
}
}
return false;
}
};