Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 597 Bytes

1309. 解码字母到整数映射.md

File metadata and controls

30 lines (25 loc) · 597 Bytes
/**
 * @param {string} s
 * @return {string}
 */
var freqAlphabets = function (s) {

    const { length } = s;

    let i = 0,
        result = ``;

    while (i < length) {
        if (i + 2 < length && s[i + 2] === '#') {
            result += decode(s[i] + s[i + 1]);
            i += 3;
        } else {
            result += decode(s[i]);
            ++i;
        }
    }
    return result;
};
function decode(key) {
    return String.fromCharCode(+key + 96);
}