Skip to content

Instantly share code, notes, and snippets.

@ssanin82
Last active August 29, 2015 14:11
Show Gist options
  • Save ssanin82/4404f8cfe0fa2e7f8913 to your computer and use it in GitHub Desktop.
Save ssanin82/4404f8cfe0fa2e7f8913 to your computer and use it in GitHub Desktop.
def get_lis(d):
p = [0 for x in xrange (len (d))]
m = [0 for x in xrange (len (d) + 1)]
l = 0
for i in xrange (len(d)):
lo = 1
hi = l
while lo <= hi:
mid = (lo + hi) / 2
if d[m [mid]] < d[i]:
lo = mid + 1
else:
hi = mid - 1
new_l = lo
p [i] = m[new_l - 1]
m [new_l] = i
if new_l > l:
l = new_l
S = [0 for x in xrange (l)]
k = m[l ]
for i in xrange (l - 1, -1 , -1):
S [i] = d[k ]
k = p[k ]
return S
print get_lis([1, 3, 4, 5, 6, 2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment