leetcode334 递增的三元子序列

class Solution {
public:
    bool increasingTriplet(vector<int>& nums) {
        //使用双指针;
        int len=nums.size();
        if(len<2) return false;
        int first=INT_MAX,second=INT_MAX;
        for(auto n: nums){
            if(n<=first)
                first=n;
            else if(n<=second)
                second=n;
            else
                return true;
        }
        return false;
    }
};

猜你喜欢

转载自www.cnblogs.com/joelwang/p/11896826.html