My problem is to create suffix array for a given string.
So far I've taken the tails of the string paired them with indexes and sorted them by strings.
I need to drop the string part of the tuple so I can return Seq[Int]
, but I don't know how to do that.
This is what I tried to do:
def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1)
You can simply map it:
seq.map(_._2)
or using pattern matching:
seq.map { case(s, i) -> i }
try
def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1).map(_._2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.