Created
January 1, 2017 23:33
-
-
Save liondancer/2f9d2a319b3d039b704007ac3702b5d9 to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence
This file contains 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 longest_increasing subsequece(arr): | |
if arr: | |
if len(arr) == 1: | |
return 1 | |
else: | |
# memoization | |
p = [1 for i in range(len(arr))] | |
for i in range(1, len(arr)): | |
for j in range(i): | |
if arr[j] < arr[i]: | |
val = p[j] + 1 | |
if val > p[i]: | |
p[i] = val | |
return max(p) | |
return 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment