We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. But sometimes it is an overkill to use these algorithms for an almost sorted array. We say an array is sorted if its ele…
class Solution: def lengthOfLIS(self,nums): if not nums:return 0 #边界处理 dp = [1 for _ in range(len(nums))] #转态的定义,dp[i]表示当前时刻的最长升序列的值 for i in range(len(nums)): #第一次从前向后遍历 for j in range(i): #从0到当前时刻遍历 if nums[j] < nums[i]: #如果出现升序的情况 dp[i] = max(dp[i…