leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0456.cpp (422B)
0 class Solution { 1 public: 2 bool find132pattern(const vector<int> &nums) { 3 int n3 = INT_MIN; 4 stack<int> st; 5 6 for (int i = nums.size() - 1; i >= 0; i--) { 7 if (nums[i] < n3) return true; 8 while (!st.empty() && st.top() < nums[i]) { 9 n3 = st.top(); 10 st.pop(); 11 } 12 st.push(nums[i]); 13 } 14 return false; 15 } 16 };