-
星空
public class Solution { public boolean find132pattern(int[] nums) { TreeMap<Integer, Integer> tm = new TreeMap<>(); for (int num : nums) { tm.put(num, tm.getOrDefault(num, 0) + 1); } int min = Integer.MAX_VALUE; for (int num : nums) { int cnt = tm.get(num); if (cnt > 1) { tm.put(num, cnt - 1); } else { tm.remove(num); } if (num <= min) { min = num; } else { Integer target = tm.higherKey(min); if (target != null && target < num) { return true; } } } return false; } }
-
星空
class Solution { public: bool find132pattern(vector<int>& nums) { int s3 = INT_MIN; stack<int> st; for( int i = nums.size()-1; i >= 0; i -- ){ if( nums[i] < s3 ) return true; else while( !st.empty() && nums[i] > st.top() ){ s3 = st.top(); st.pop(); } st.push(nums[i]); } return false; } };
-
星空
class Solution { public boolean find132pattern(int[] nums) { for (int i = 0; i < nums.length; i++) { for (int j = i + 1; j < nums.length; j++) { for (int k = j + 1; k < nums.length; k++) { if (nums[i] < nums[k] && nums[k] < nums[j]) return true; } } } return false; } }
-
星空
class Solution { public boolean find132pattern(int[] nums) { for (int n = nums.length, i = n - 1, top = n, third = Integer.MIN_VALUE; i >= 0; i--) { if (nums[i] < third) return true; while (top < n && nums[i] > nums[top]) third = nums[top++]; nums[--top] = nums[i]; } return false; } }
-