Python - Simple DP Solution

  • 0
    class Solution(object):
        def lengthOfLIS(self, nums):
            :type nums: List[int]
            :rtype: int
            if not nums:
                return 0
            dp = [1 for x in range(len(nums))]
            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)
            return max(dp)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.