개발 일기

알고리즘 연습 본문

알고리즘

알고리즘 연습

이건욱

https://school.programmers.co.kr/learn/courses/30/lessons/152995

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

function solution(scores) {
    const wanho = scores[0];
    scores.sort((a,b) => a[0] === b[0] ? a[1] - b[1] : b[0] - a[0]);
    let answer = 1;
    let maxScore = 0;
    const wanhoSum = wanho[0] + wanho[1];
    for(let score of scores){
       
        if(score[1] < maxScore) {
            if(score === wanho) return -1;
        } else {
            maxScore = Math.max(maxScore, score[1]);
            if(score[0] + score[1] > wanhoSum){
                answer++;
            }
        }
    }
    return answer;
}

'알고리즘' 카테고리의 다른 글

알고리즘 연습  (0) 2023.02.20
알고리즘 연습  (0) 2023.02.20
알고리즘 연습  (0) 2023.02.20
Comments