Guest User

Untitled

a guest
Oct 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. object Main {
  2.  
  3. def main(args: Array[String]): Unit = {
  4. println(charIndex("Missisipi"))
  5. //var s = scala.collection.immutable.SortedSet[Int]()
  6. }
  7.  
  8. def charIndex(s: String) : scala.collection.mutable.Map[Char, scala.collection.mutable.TreeSet[Int]] = {
  9. val m = scala.collection.mutable.Map[Char, scala.collection.mutable.TreeSet[Int]]()
  10. s.zipWithIndex.foreach{
  11. case (c, i) => m += c -> (m.getOrElse(c, scala.collection.mutable.TreeSet()) += i)
  12. }
  13. m
  14. }
  15. }
  16.  
  17. case ( c, i ) => m += c -> ( m.getOrElse( c, scala.collection.mutable.TreeSet[Int]() ) += i)
  18.  
  19. scala.collection.mutable.TreeSet()
  20.  
  21. new TreeSet()(implicit ord: Ordering[A])
Add Comment
Please, Sign In to add comment