📌  相关文章
📜  候鸟hackerrank解决方案javascript代码示例

📅  最后修改于: 2022-03-11 15:01:31.446000             🧑  作者: Mango

代码示例1
// migratory birds hackerrank solution javascript
function migratoryBirds(arr) {
    let map = {}, maxCount = 0, output = [];
    for (let i = 0; i < arr.length; i++) {
        if (!map[arr[i]]) {
            map[arr[i]] = 1;
        } else {
            map[arr[i]] += 1;
        }
        if (map[arr[i]] > maxCount) {
            maxCount = map[arr[i]];
        }
    }
    for (let j = 0; j < arr.length; j++) {
        if (map[arr[j]] === maxCount) {
            output.push(arr[j]);
        }
    }
    return Math.min(...output);
}