精華區beta Marginalman 關於我們 聯絡資訊
只有這種跟easy沒兩樣的medium才寫得出來了 3163. String Compression III public string CompressedString(string word) { if (word.Length == 1) { return $"1{word}"; } var result = new StringBuilder(); var lastCharacter = word[0]; var lastCount = 1; for (int i=1;i<word.Length;i++) { if (word[i] == word[i-1] & lastCount < 9) { lastCount++; } else { result.Append($"{lastCount}{word[i - 1]}"); lastCount = 1; lastCharacter = word[i]; } } result.Append($"{lastCount}{word[word.Length-1]}"); return result.ToString(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.230.58.252 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1730742148.A.0BE.html ※ 編輯: devilkool (36.230.58.252 臺灣), 11/05/2024 01:43:11