def indexes(word:String)={
val charToInts = new mutable.HashMap[Char,SortedSet[Int]]()
var i =0
word.foreach(char =>{
charToInts.get(char) match {
case Some(set) => charToInts(char)=set+i
case None => charToInts(char)=SortedSet(i)
}
i+=1
})
charToInts
}
2. 重复前一个练习,这次用字符到列表的不可变映射。
def indexes(word:String)={
var charToInts = new collection.immutable.HashMap[Char,SortedSet[Int]]()
var i = 0
word.foreach(char=>{
charToInts.get(char) match {
case Some(set) => set+i
ca