Skip to content

Commit

Permalink
add Hao's implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
haoel committed Mar 21, 2019
1 parent 054e426 commit 1b0bf37
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Source : https://leetcode.com/problems/increasing-triplet-subsequence/
// Author : Calinescu Valentin
// Author : Calinescu Valentin, Hao Chen
// Date : 2016-02-27

/***************************************************************************************
Expand Down Expand Up @@ -41,3 +41,25 @@ class Solution {
return solution;
}
};


//Hao Chen's implementation
class Solution {
public:
bool increasingTriplet(vector<int>& nums) {
if (nums.size() < 3) return false;

int first=INT_MAX, second = INT_MAX;

for(int i=0; i<nums.size(); i++) {
if ( first > nums[i] ) {
first = nums[i];
}else if ( first < nums[i] && nums[i] < second) {
second = nums[i];
}else if (nums[i] > second){
return true;
}
}
return false;
}
};

0 comments on commit 1b0bf37

Please sign in to comment.