Last active
October 1, 2020 19:58
-
-
Save lovasoa/6733017 to your computer and use it in GitHub Desktop.
Solution to the longest increasing subsequence problem, in 5 lines of python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lis(a): | |
L = [] | |
for (k,v) in enumerate(a): | |
L.append(max([L[i] for (i,n) in enumerate(a[:k]) if n<v] or [[]], key=len) + [v]) | |
return max(L, key=len) | |
inp = [int(a) for a in input("List of integers: ").split(' ')] | |
print(lis(inp)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wow!!! nice work