1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| class Solution { public int lengthOfLIS(int[] nums) { int n = nums.length; if (n == 0) { return 0; }
int[] dp = new int[n]; for (int i = 0; i < n; i++) { dp[i] = 1; }
for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] > nums[j]) { dp[i] = Math.max(dp[i], dp[j] + 1); } } }
int res = dp[0]; for (int i = 0; i < n; i++) { res = Math.max(res, dp[i]); } return res; } }
|