aboutsummaryrefslogtreecommitdiff
path: root/increasing_triplet_subsequence.cpp
blob: 41a9f0e659aef193a884c4864afc4fbf67878991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "leetcode.h"

class Solution {
public:
  bool increasingTriplet(vector<int> &nums) {
    int one = INT_MAX, two = INT_MAX;
    for (auto n : nums) {
      if (n <= one)
        one = n;
      else if (n <= two)
        two = n;
      else
        return true;
    }
    return false;
  }
};

int main() {
  Solution obj;
  vector<int> nums = {1, 2, 3, 4, 5};
  if (obj.increasingTriplet(nums))
    cout << "true";
  else
    cout << "false";
}