mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
Merge pull request #359 from z80160280/z80160280-patch-8
Update 0300.最长上升子序列.md
This commit is contained in:
@ -130,7 +130,20 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def lengthOfLIS(self, nums: List[int]) -> int:
|
||||||
|
if len(nums) <= 1:
|
||||||
|
return len(nums)
|
||||||
|
dp = [1] * len(nums)
|
||||||
|
result = 0
|
||||||
|
for i in range(1, len(nums)):
|
||||||
|
for j in range(0, i):
|
||||||
|
if nums[i] > nums[j]:
|
||||||
|
dp[i] = max(dp[i], dp[j] + 1)
|
||||||
|
result = max(result, dp[i]) #取长的子序列
|
||||||
|
return result
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
```go
|
```go
|
||||||
|
Reference in New Issue
Block a user