leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0456.cpp (422B)


      1 class Solution {
      2   public:
      3     bool find132pattern(const vector<int> &nums) {
      4         int n3 = INT_MIN;
      5         stack<int> st;
      6 
      7         for (int i = nums.size() - 1; i >= 0; i--) {
      8             if (nums[i] < n3) return true;
      9             while (!st.empty() && st.top() < nums[i]) {
     10                 n3 = st.top();
     11                 st.pop();
     12             }
     13             st.push(nums[i]);
     14         }
     15         return false;
     16     }
     17 };