300. Longest Increasing Subsequence
Last updated
Last updated
/**
* Time complexity :
* Space complexity :
*/
class Solution {
public int lengthOfLIS(int[] nums) {
if(nums == null || nums.length == 0) {
return 0;
}
int n = nums.length, maxLen = 1;
int[] dp = new int[n];
Arrays.fill(dp, 1);
for(int i = 1; i < n; i++) {
for(int j = 0; j < i; j++) {
if(nums[i] > nums[j] && dp[j]+1 > dp[i]) {
dp[i] = dp[j]+1;
}
}
if(dp[i] > maxLen) {
maxLen = dp[i];
}
}
return maxLen;
}
}