λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
"곡뢀" π‘Ÿπ‘’π‘π‘œπ‘Ÿπ‘‘/π΄π‘™π‘”π‘œπ‘Ÿπ‘–π‘‘β„Žπ‘š

[JS/ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€] / [2021 Dev-Matching] 둜또의 졜고 μˆœμœ„μ™€ μ΅œμ € μˆœμœ„

by ΰ·† Yoni ΰ·† 2022. 2. 16.
728x90

[2021 Dev-Matching] λ‘œλ˜μ˜ μ΅œκ³  μˆœμœ„와 μ΅œμ € μˆœμœ„

 

 

 

μ½”λ”©ν…ŒμŠ€νŠΈ μ—°μŠ΅ - 둜또의 졜고 μˆœμœ„μ™€ μ΅œμ € μˆœμœ„

둜또 6/45(μ΄ν•˜ '둜또'둜 ν‘œκΈ°)λŠ” 1λΆ€ν„° 45κΉŒμ§€μ˜ 숫자 쀑 6개λ₯Ό μ°μ–΄μ„œ λ§žνžˆλŠ” λŒ€ν‘œμ μΈ λ³΅κΆŒμž…λ‹ˆλ‹€. μ•„λž˜λŠ” 둜또의 μˆœμœ„λ₯Ό μ •ν•˜λŠ” λ°©μ‹μž…λ‹ˆλ‹€. 1 μˆœμœ„ 당첨 λ‚΄μš© 1 6개 λ²ˆν˜Έκ°€ λͺ¨λ‘ 일치 2 5개 번호

programmers.co.kr

 

My μ½”λ“œ

function solution(lottos, win_nums) {
    var answer = [];
    let max;
    let min;
    let cnt_win = 0;
    let cnt_zero = 0;

    for(let i=0;i<lottos.length;i++) {
        if(lottos[i] == 0)
            cnt_zero += 1;
    }
    for(let i=0;i<lottos.length;i++) {
        if(win_nums.includes(lottos[i])) {
            cnt_win += 1;
        }
    }

    min = checkRank(cnt_win);
    max = min - cnt_zero;

    if(cnt_zero == 6) {
        min = 6;
        max = 1;
    }
    answer = [max, min];
    return answer;
}
function checkRank(cnt_win) {
    if(cnt_win < 2){
        return 6;
    } else if (cnt_win == 2) {
        return 5;
    } else if (cnt_win == 3) {
        return 4;
    } else if (cnt_win == 4) {
        return 3;
    } else if (cnt_win == 5) {
        return 2;
    } else if (cnt_win == 6) {
        return 1;
    }
}

 

λ‹€λ₯Έ μ‚¬λžŒμ˜ 풀이

function solution(lottos, win_nums) {
    const rank = [6, 6, 5, 4, 3, 2, 1];

    let minCount = lottos.filter(v => win_nums.includes(v)).length;
    let zeroCount = lottos.filter(v => !v).length;

    const maxCount = minCount + zeroCount;

    return [rank[maxCount], rank[minCount]];
}

 

728x90

λŒ“κΈ€