1 Star 0 Fork 1

Jeremy Lee/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
longest_increasing_subsequence_length.py 488 Bytes
一键复制 编辑 原始数据 按行查看 历史
'''
Author- DIWAKAR JAISWAL
find lenth Longest increasing subsequence of given array.
'''
def lis(a):
n=len(a)
#initialize ans array same lenth as 1
ans=[1]*n
for i in range(1,n):
#now compare with first index to that index
for j in range(i):
if a[i]>a[j] and ans[i]<ans[j]+1:
ans[i]=ans[j]+1
return max(ans)
a=[1,3,2,6,4]
#longest increasing subsequence=[{1<3<6},{1<3<4},{1<2<6},{1<2<4}] length is 3
print("Maximum Length of longest increasing subsequence ",lis(a))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Jelmy/Python-1.git
[email protected]:Jelmy/Python-1.git
Jelmy
Python-1
Python-1
master

搜索帮助