Python generic short O(N^2) solution


  • 0
    I
    def lengthOfLIS(self, nums):
        if not nums: return 0
        dp=[1]*len(nums)
        for i in range(len(nums)):
            for j in range(i):
                if nums[j]<nums[i] and dp[j]+1>dp[i]: 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.