You are viewing a single comment's thread. Return to all comments →
f# solution
let rec compress n list = match list with | [] -> [] | [ c ] when n = 1 -> [ c ] | [ c ] -> [ c; string n ] | x :: xs when x = List.head xs -> compress (n + 1) xs | x :: xs when n = 1 -> x :: compress 1 xs | x :: xs -> x :: string n :: compress 1 xs open System [<EntryPoint>] let main _ = Console.ReadLine() |> Seq.toList |> List.map string |> compress 1 |> String.concat "" |> Console.WriteLine 0
Seems like cookies are disabled on this browser, please enable them to open this website
String Compression
You are viewing a single comment's thread. Return to all comments →
f# solution