Seawolf 发表于 2020-8-4 00:52:25

Leetcode 300. Longest Increasing Subsequence

Given an unsorted array of integers, find the length of longest increasing subsequence.

Example:

Input:
Output: 4
Explanation: The longest increasing subsequence is , therefore the length is 4.
Note:

There may be more than one LIS combination, it is only necessary for you to return the length.
Your algorithm should run in O(n2) complexity.
Follow up: Could you improve it to O(n log n) time complexity?

class Solution:
    def lengthOfLIS(self, nums: List) -> int:
      if nums == None or len(nums) == 0:
            return 0
      dp =
      res = 1
      for i in range(len(nums)):
            for j in range(i + 1, len(nums)):
                if nums > nums:
                  dp = max(dp, dp + 1)
                res = max(res, dp)
      return res
页: [1]
查看完整版本: Leetcode 300. Longest Increasing Subsequence