题解 | #字符串编码#
字符串编码
https://www.nowcoder.com/practice/56a487c342a64d2ea4c3a0b0144b42d0
// 一个循环搞定
void (async function () {
const str = await readline();
let tep = "", count = 0, res = ""
for (const char of str) {
if (tep != char) {
if (tep != "") {
res += `${count}${tep}`;
}
count = 1;
} else {
count++;
}
tep = char;
}
res += `${count}${tep}`
console.log(res)
})();
