思路:
方法一:DP。
时间复杂度O(N^2),空间复杂度O(N)。
java code :
public class Solution {
public int lengthOfLIS(int[] nums) {
if(nums == null || nums.length == 0) return 0;
int[] dp = new int[nums.length];
Arrays.fill(dp, 1);
int ans = 1;
for(int i = 0; i < nums.length; ++i) {
for(int j = 0; j < i; ++j) {
if(nums[j] < nums[i]) {
dp[i] = Integer.max(dp[i], dp[j] + 1);
}
}
ans = dp[i] > ans ? dp[i] : ans;
}
return ans;
}
}