Update 0300.最长上升子序列.md

This commit is contained in:
Baturu 2021-06-07 22:14:23 -07:00 committed by GitHub
parent a4b7399acb
commit 667a2a6e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -130,7 +130,20 @@ class Solution {
```
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