摘要: 快速排序-数组 def partition(arr,low,high): i = ( low-1 ) # 最小元素索引 pivot = arr[high] for j in range(low , high): # 当前元素小于或等于 pivot if arr[j] <= pivot: i = i+ 阅读全文
posted @ 2020-09-25 19:17 yourText 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 最长回文子串 def solution(s): maxlen = 0 maxstr = '' for i in range(len(s)): for j in range(i+1): if len(s[j:i+1])<=maxlen:#优化,减少循环 break if s[j:i+1]==s[j:i 阅读全文
posted @ 2020-09-25 19:15 yourText 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 最长递增子序列问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱) 例如:给定一个长度为8的数组A{1,3,5,2,4,6,7,8},则其最长的单调递增子序列为{1,2,4,6,7,8},长度为6. def solution(num): dp = [1]*len( 阅读全文
posted @ 2020-09-25 08:43 yourText 阅读(131) 评论(0) 推荐(0) 编辑