我的问题是为给定的字符串创建后缀数组。到目前为止,我已经将字符串的尾部与索引配对,并按字符串对它们进行了排序。我需要删除元组的字符串部分,以便返回Seq[Int]
,但我不知道该怎么做。
这是我试图做的:
def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1)
您可以简单地将其映射:
seq.map(_._2)
或使用模式匹配:
seq.map { case(s, i) -> i }
尝试
def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1).map(_._2)