콘솔창 & 윈도우창/코딩 테스트

프로그래머스 LV.2 롤케이크 자르기

뽀또치즈맛 2025. 3. 30. 12:42

GitHub :

https://github.com/kwon1232/CodingTest/tree/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/2/132265.%E2%80%85%EB%A1%A4%EC%BC%80%EC%9D%B4%ED%81%AC%E2%80%85%EC%9E%90%EB%A5%B4%EA%B8%B0

 

CodingTest/프로그래머스/2/132265. 롤케이크 자르기 at main · kwon1232/CodingTest

This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - kwon1232/CodingTest

github.com

 

 

 

 

#include <string>
#include <vector>
#include <map>

using namespace std;

int solution(vector<int> topping) {
    int answer = 0;
    map<int, int> m1, m2; 
    
    for(int i = 0; i < topping.size(); i++)
    {
        m1[topping[i]]++;
    }
    for(int i = 0; i < topping.size(); i++)
    {
        m1[topping[i]]--;
        m2[topping[i]]++;
        
        if(m1[topping[i]] == 0)
            m1.erase(topping[i]);
        if(m1.size() == m2.size())
            answer++;
    }
    
    return answer;
}

 

 

 

 

문제 링크


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