mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 12:15:58 +08:00
Update 0300.最长上升子序列.md
This commit is contained in:
@ -110,7 +110,26 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
Java:
|
Java:
|
||||||
|
```Java
|
||||||
|
class Solution {
|
||||||
|
public int lengthOfLIS(int[] nums) {
|
||||||
|
int[] dp = new int[nums.length];
|
||||||
|
Arrays.fill(dp, 1);
|
||||||
|
for (int i = 0; i < dp.length; i++) {
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
if (nums[i] > nums[j]) {
|
||||||
|
dp[i] = Math.max(dp[i], dp[j] + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int res = 0;
|
||||||
|
for (int i = 0; i < dp.length; i++) {
|
||||||
|
res = Math.max(res, dp[i]);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user