Участник:Rimon/Longest Increasing Subsequence

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/longest-increasing-subsequence/

from typing import List
class Solution:
    def lengthOfLIS(self, nums: List[int]) -> int:
        length = len(nums)
        if length == 0:
            return 0
        dp = [1] * (length + 1)
        lis = 1  
        for i in range(length):
            for j in range(i):
                if nums[i] > nums[j]:
                    if dp[j] + 1 > dp[i]:  
                        dp[i] = dp[j] + 1
            lis = max(dp[i], lis)
        return lis