【数组】递增的三元子序列

题目:

解答:

 1 class Solution {
 2 public:
 3     bool increasingTriplet(vector<int>& nums) 
 4     {
 5         int len = nums.size();
 6         
 7         if (len < 3) 
 8         {
 9             return false;
10         }
11         
12         int small = INT_MAX;
13         int mid = INT_MAX;
14         
15         for (auto num : nums) 
16         {
17           if (num <= small) 
18           {
19             small = num;
20           } else if (num <= mid) 
21           {
22             mid = num;
23           } 
24           else if (num > mid) 
25           {
26             return true;
27           }
28         }
29         return false;    
30 
31     }
32 };

猜你喜欢

转载自www.cnblogs.com/ocpc/p/12900180.html