334 Increasing Triplet Subsequence
1. Question
2. Implementation
class Solution {
public boolean increasingTriplet(int[] nums) {
if (nums == null || nums.length <= 2) {
return false;
}
int n = nums.length;
int[] dp = new int[n];
Arrays.fill(dp, 1);
int maxLen = 1;
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i] && dp[j] + 1 > dp[i]) {
dp[i] = dp[j] + 1;
}
maxLen = Math.max(maxLen, dp[i]);
if (maxLen >= 3) {
return true;
}
}
}
return false;
}
}3. Time & Space Complexity
Last updated