Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 619 Bytes

1704. 判断字符串的两半是否相似.md

File metadata and controls

32 lines (27 loc) · 619 Bytes
/**
 * @param {string} s
 * @return {boolean}
 */
var halvesAreAlike = function (s) {
    const mid = s.length >>> 1;
    let left = 0,
        right = s.length - 1,
        count = 0;

    while (left < mid && right >= mid) {
        if (isVowel(s[left])) {
            ++count;
        }
        if (isVowel(s[right])) {
            --count;
        }
        ++left;
        --right;
    }

    return !count;
};

function isVowel(ch) {
    return "aeiouAEIOU".includes(ch);
}