-
프로그래머스 롤케이크자르기 c++알고리즘/프로그래머스 2022. 11. 8. 18:32반응형
https://school.programmers.co.kr/learn/courses/30/lessons/132265
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string> #include <vector> #include <set> using namespace std; int bro_topping[10001]; int me_topping[10001]; set<int> bro; set<int> me; int solution(vector<int> topping) { int answer = 0; for(auto i : topping) { me_topping[i]++; me.insert(i); } for(auto i : topping) { bro_topping[i]++; bro.insert(i); me_topping[i]--; if(me_topping[i] == 0) { me.erase(i); } if(me.size() == bro.size()) { answer++; } } return answer; }
투포인터를 사용하면 쉽게 풀수 있는 문제.
728x90반응형'알고리즘 > 프로그래머스' 카테고리의 다른 글
프로그래머스 숫자 카드 나열 c++ (0) 2022.11.27 프로그래머스 귤 고르기 c++ (2) 2022.11.26 프로그래머스 택배상자 c++ (0) 2022.10.14 프로그래머스 연속 부분 수열 합의 개수 c++ (0) 2022.10.14 프로그래머스 할인행사 c++ (1) 2022.10.13