求助,牛客笔试是否有bug?

求助,今天做的一个笔试题:求字符串中出现多次字母和数字的次数,本来很简单的题,为什么牛客上就是不通过?
我的代码:
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 *
 * @param str string字符串
 * @return int整型
 */
function maxCount(str) {
    // 我的代码没问题,不知道为什么通过不了用例,可否解答?
    let count = {};
    let lowerStr = str.toLowerCase();
    if (str.length == 0 || str == "") {
        return 0;
    }
    if (str.length == 1) {
        return 1;
    }

    for (let i = 0; i < lowerStr.length; i++) {
        let c = lowerStr[i];
if ((c >= "a" && c <= "z") || (c >= "0" && c <= "9")) {
            if (count[c]) {
                count[c]++;
            } else {
                count[c] = 1;
            }
        }
    }
    let res = 0;

    for (let c in count) {
if (count[c] > 1) {
            res = Math.max(count[c], res);
        }
    }
    return res;
}
全部评论
你这个题,我好像也做过,关键是我当时看那题目好像例子就有问题。四不像的感觉
点赞
送花
回复
分享
发布于 2023-09-09 20:25 安徽

相关推荐

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