Created
December 7, 2009 12:51
-
-
Save banyan/250802 to your computer and use it in GitHub Desktop.
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
# 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