Skip to content

Instantly share code, notes, and snippets.

@banyan
Created December 7, 2009 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banyan/250802 to your computer and use it in GitHub Desktop.
Save banyan/250802 to your computer and use it in GitHub Desktop.
# coding: utf-8
def get_suffix_array(str)
hash = {}
str.size.times do | i |
hash[i + 1] = str.slice(i, str.size)
end
a = []
hash.each do | x, y |
a << y
end
suffix = []
a.sort.each do | n |
hash.each do | x, y |
suffix << x if n == y
end
end
suffix
end
a = get_suffix_array('abcbccab')
p a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment