본문 바로가기
Coding Test/Programmers

[Programmers] Lv 2. 롤케이크 자르기

by song.ift 2023. 7. 21.

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

 

프로그래머스

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

programmers.co.kr

 

#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

int solution(vector<int> topping) {
    map<int, int> a, b;
    
    std::for_each(topping.begin(), topping.end(), [&](const auto& t) { ++b[t]; });
    return std::accumulate(topping.begin(), topping.end(), 0, [&](auto acc, const auto& t) {
        ++a[t], --b[t];
        if (b[t] == 0) b.erase(t);
        return (a.size() == b.size()) ? acc + 1 : acc;
    });
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/commit/5e7e9b33add658e267756ac2bbea708942716d83

 

[unrated] Title: 롤케이크 자르기, Time: 159.15 ms, Memory: 37 MB -BaekjoonHub · developeSHG/Algorithm-Baekjoon_Programme

developeSHG committed Jul 21, 2023

github.com

 

댓글