Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Medium/IncreasingTripletSequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//334. https://leetcode.com/problems/increasing-triplet-subsequence/

public class IncreasingTripletSequence
{
public static void main(String[] args)
{
int[] nums = {1,2,3,4,5};
boolean ans = increasingTriplet(nums);
System.out.println(ans);
}

public static boolean increasingTriplet(int[] nums)
{
int small = Integer.MAX_VALUE;
int big = Integer.MAX_VALUE;

//Greedy
for(int i=0; i<nums.length; i++)
{
if(nums[i] <= small)
small = nums[i];
else if (small <= nums[i] && nums[i] <= big)
big = nums[i];
else
return true;
}

return false;
}
}