nikunjsoni

456

Apr 7th, 2021
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     bool find132pattern(vector<int>& nums) {
  4.         bool found = false;
  5.         stack<int> stk;
  6.         int sz = nums.size(), num2;
  7.        
  8.         num2 = INT_MIN;
  9.         for(int i=sz-1; i>=0; i--){
  10.             if(nums[i] < num2) found = true;
  11.             while(!stk.empty() && stk.top() < nums[i]){
  12.                 num2 = max(num2, stk.top());
  13.                 stk.pop();
  14.             }
  15.             stk.push(nums[i]);
  16.         }
  17.         return found;
  18.     }
  19. };
RAW Paste Data