-
[programmers] 폰켓몬 / C++공부/PS (programmers) 2022. 7. 27. 00:54
https://school.programmers.co.kr/learn/courses/30/lessons/1845
#include <vector> #include <set> #include <iostream> using namespace std; set <int> pokemon; int solution(vector<int> nums) { int answer = 0; int N = nums.size(); // 1 - 10000 for(int i=0; i<nums.size(); i++) { pokemon.insert(nums[i]); } /* set<int>::iterator iter; for(iter = pokemon.begin(); iter != pokemon.end(); iter++) { cout << "*iter: " << *iter << "\n"; } */ if(pokemon.size() > N/2) answer = N/2; else answer = pokemon.size(); return answer; }
set 컨테이너를 이용해서 중복없이 폰켓몬들의 번호를 저장해주었다
'공부 > PS (programmers)' 카테고리의 다른 글
[programmers] 이상한 문자 만들기 / C++ (0) 2022.07.20 [programmers] 제일 작은 수 제거하기 / C++ (0) 2022.07.19 [programmers] 소수 만들기 / C++ (0) 2022.07.19 [programmers] 두 개 뽑아서 더하기 / C++ (0) 2022.07.19 [programmers] 프린터 / C++ (0) 2022.05.18