Run-length encoding
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
これはまだ完了していないレッスンの先にある内容です。まずはそのレッスンを済ませてください:
Python Basics · Functions →
ラン長符号化
ストリングを圧縮します。同じ文字の連続する部分(run)を、その文字 followed by 繰り返しの回数に置き換えます: aaabbc → a3b2c1 。回数が 1 でも必ず書き出します。
ストリングを巡り、現在の文字とそのrunの長さを追跡します。次の文字が異なれば、runを書き出して(文字+回数)、新しいrunを始めます。ループ終了後に最後のrunを書き出すのを忘れないでください。
難易度 5/5 · 400 コイン + 今日初回達成時の小ボーナス
Write run_length_encode(s) that compresses runs of the same character into the character followed by its run length, e.g. aaabbc becomes a3b2c1. Always include the count, even when it is 1.
実行ボタンをクリックして出力を確認してください。