Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Main {
- def main(args: Array[String]): Unit = {
- println(charIndex("Missisipi"))
- //var s = scala.collection.immutable.SortedSet[Int]()
- }
- def charIndex(s: String) : scala.collection.mutable.Map[Char, scala.collection.mutable.TreeSet[Int]] = {
- val m = scala.collection.mutable.Map[Char, scala.collection.mutable.TreeSet[Int]]()
- s.zipWithIndex.foreach{
- case (c, i) => m += c -> (m.getOrElse(c, scala.collection.mutable.TreeSet()) += i)
- }
- m
- }
- }
- case ( c, i ) => m += c -> ( m.getOrElse( c, scala.collection.mutable.TreeSet[Int]() ) += i)
- scala.collection.mutable.TreeSet()
- new TreeSet()(implicit ord: Ordering[A])
Add Comment
Please, Sign In to add comment