Very Concise TreeSet Sol.


  • 0
    O
        public boolean find132pattern(int[] nums) {
            TreeSet<Integer> set_raw = new TreeSet(), set_hit = new TreeSet();
            for (int i = nums.length - 1; i >= 0; i--) {
                if (set_hit.higher(nums[i]) != null) return true;
                set_raw.add(nums[i]);
                Integer t = set_raw.lower(nums[i]);
                if (t != null) set_hit.add(t);
            }
            return false;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.