Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created January 1, 2017 23:33
Show Gist options
  • Save liondancer/2f9d2a319b3d039b704007ac3702b5d9 to your computer and use it in GitHub Desktop.
Save liondancer/2f9d2a319b3d039b704007ac3702b5d9 to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence
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