aboutsummaryrefslogtreecommitdiff
path: root/other/increasing_triplet_subsequence.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/increasing_triplet_subsequence.cpp')
-rw-r--r--other/increasing_triplet_subsequence.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/other/increasing_triplet_subsequence.cpp b/other/increasing_triplet_subsequence.cpp
new file mode 100644
index 0000000..41a9f0e
--- /dev/null
+++ b/other/increasing_triplet_subsequence.cpp
@@ -0,0 +1,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";
+}