Skip to content

Commit dec52b4

Browse files
Merge pull request PawanJaiswal08#26 from aryangulati/patch-1
Create 132-pattern.cpp
2 parents 1e32c8c + b57a22b commit dec52b4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

132-pattern.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
bool find132pattern(vector<int>& nums) {
4+
int ak = numeric_limits<int>::min();
5+
stack<int> st;
6+
for (int i = nums.size() - 1; i >= 0; --i) {
7+
if (nums[i] < ak) {
8+
return true;
9+
} else {
10+
while (!st.empty() && nums[i] > st.top()) {
11+
ak = st.top(), st.pop();
12+
}
13+
}
14+
st.emplace(nums[i]);
15+
}
16+
return false;
17+
}
18+
};

0 commit comments

Comments
 (0)