Make Unreal REAL.
article thumbnail
Level 3. 숫자 게임

 

 

최소힙을 구성하고 앞에서부터 비교하면서, B가 더 커 점수를 얻을 수 있는 경우 A의 다음 숫자와 비교하면 된다.

 

레벨 3 문제는 아닌 것 같다..

 

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int solution(vector<int> A, vector<int> B)
{
    int answer = 0;
    priority_queue<int, vector<int>, greater<int>> pqA, pqB;

    for (int num : A) pqA.emplace(num);
    for (int num : B) pqB.emplace(num);

    while (!pqB.empty())
    {
        if (pqA.top() < pqB.top())
            ++answer,
            pqA.pop();

        pqB.pop();
    }

    return answer;
}
profile

Make Unreal REAL.

@diesuki4

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그