GeniusOfCX

导航

leetcode 456 rust

题目

代码

pub fn find132pattern(nums: Vec<i32>) -> bool {
    let mut mn = nums[0];
    let mut vec:Vec<(i32,i32)> = Vec::new();
    for &num in nums.iter().skip(1){
        if num < mn {
            mn = num;
            continue;
        }
        while !vec.is_empty() && num > vec.last().unwrap().0 {
            let (_,left) = vec.pop().unwrap();
            if left > num {
                return true;
            }
        }
        vec.push((mn,num));
    }
    false

}

posted on 2021-04-08 13:50  GeniusOfCX  阅读(92)  评论(0编辑  收藏  举报