Lv1. 폰켓몬

Hello·2022년 7월 5일
0

코딩테스트 연습 > 폰켓몬

풀이 설명
N마리 포켓몬 중에 최대 N/2마리만 가질 수 있으며
같은 숫자는 같은 종류의 폰켓몬이므로 set 으로 처리한다. (중복제거)

나의 풀이

def solution(nums):
    len_lst = len(nums)
    len_set = len(set(nums))
    if len_set < len_lst/2:
        return len_set 
    else:
        return len_lst/2

다른 사람의 풀이

def solution(nums):
    return min(len(nums)/2, len(set(nums)))

배운점
1. list to set: set(list)
2. list, set 의 길이: len(set), len(list)
3. 둘 중 작은 값: min(int, int)

profile
안녕하세요 :)

0개의 댓글