-
[Python] 폰켓몬Algorithm/프로그래머스 2021. 5. 3. 23:21
1. 문제 📚
2. 입출력 예 📋
3. 알고리즘 ✅
- 가장 많은 종류의 폰켓몬을 갖고 싶어하기 때문에 박사님이 가지고 있는 폰켓몬 /2 만큼 중복제거를 해준다
4. 소스코드 💻
def solution(nums): count=len(nums)//2 poketmon = [] for i in nums: if poketmon.count(i) == 0: poketmon.append(i) return len(poketmon[:count])
5. 다른사람의 풀이 💻
def solution(nums): return min(len(nums)/2, len(set(nums)))
앞으로는 if 절로 중복을 제거하는 방법보단 set을 이용하자! 😅
'Algorithm > 프로그래머스' 카테고리의 다른 글
[Python] 입국심사 (0) 2021.06.03 [Python] 로또의 최고 순위와 최저 순위 (0) 2021.05.05 [Python] 2016년 (0) 2021.05.01 [Python] 체육복 (0) 2021.05.01 [Python] 모의고사 (0) 2021.04.29