You are viewing a single comment's thread. Return to all comments →
Scala
import scala.io.StdIn.readLine object Solution { def main(args: Array[String]) { def swap(str: List[Char]): List[Char] = { def swap(res: List[Char], str: List[Char]): List[Char] = { str match { case a :: b :: tail => swap(res :+ b :+ a, tail) case Nil => res } } swap(Nil, str) } val n = readLine().toInt for (i <- 1 to n) { val str = readLine() println(swap(str.toList).mkString) } } }
Seems like cookies are disabled on this browser, please enable them to open this website
String-o-Permute
You are viewing a single comment's thread. Return to all comments →
Scala