题解 | #字符串编码#

字符串编码

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)
})();

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务