Advertisement
STANAANDREY

ch3 21/12/2019 O(n^2)

Dec 22nd, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Solution
  5. {
  6. private:
  7.     const int NMAX = 15005;
  8. public:
  9.     inline bool find132pattern(vector <int>& nums)
  10.     {
  11.         int minVal[NMAX] = {};
  12.         minVal[0] = nums.front();
  13.         for (int i = 1; i < (int)nums.size(); i++)
  14.             minVal[i] = min(minVal[i - 1], nums[i]);
  15.  
  16.         for (int j = 1; j < (int)nums.size() - 1; j++)
  17.             for (int k = j + 1; k < (int)nums.size(); k++)
  18.                 if (minVal[j - 1] < nums[k] && nums[k] < nums[j])
  19.                     return true;
  20.         return false;
  21.     }
  22. };
  23.  
  24. int main()
  25. {
  26.     vector <int> v{1,3,4};
  27.     Solution *sol = new Solution();
  28.     cout << sol -> find132pattern(v);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement