Seq [String,Int]到Scala中的Seq [Int]

问题描述 投票:-1回答:2

我的问题是为给定的字符串创建后缀数组。到目前为止,我已经将字符串的尾部与索引配对,并按字符串对它们进行了排序。我需要删除元组的字符串部分,以便返回Seq[Int],但我不知道该怎么做。

这是我试图做的:

def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1)
scala functional-programming scala-collections seq
2个回答
2
投票

您可以简单地将其映射:

seq.map(_._2)

或使用模式匹配:

seq.map { case(s, i) -> i }

1
投票

尝试

def suffixArray(s: String): Seq[Int] = s.tails.zipWithIndex.toSeq.sortBy(_._1).map(_._2)
© www.soinside.com 2019 - 2024. All rights reserved.