求助,牛客笔试是否有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" &amp;&amp; c <= "z") || (c >= "0" &amp;&amp; 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 安徽

相关推荐

不愿透露姓名的神秘牛友
07-01 11:47
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务