You are viewing a single comment's thread. Return to all comments →
it works , but for some tests it is too slow :(
val s = StdIn.readLine().toList def grouping (acc: String, lst: List[Char]): List[String] = lst match { case Nil => acc :: Nil case h::Nil => if (h != acc(0)) acc :: h.toString :: Nil else acc+h.toString :: Nil case h::tail => if (h != acc(0)) acc :: grouping(h.toString,tail) else grouping(acc+h.toString,tail) } val x = grouping(s.head.toString,s.tail) val y = x.map(a => { if (a.length > 1) a(0) + a.length.toString else a(0) }).mkString("") println(y) }
String Compression
You are viewing a single comment's thread. Return to all comments →
it works , but for some tests it is too slow :(