문제

 

내가 작성한 코드
def solution(nums):
    choice_p = int(len(nums) / 2)
    index_p = list(set(nums))

    if choice_p >= len(index_p):
        return len(index_p)
    else:
        return choice_p

 

코드 설명
choice_p = int(len(nums) / 2)
index_p = list(set(nums))

> choice_p : nums 변수에 있는 포켓몬들 중 선택할 수 있는 포켓몬의 수

> index_p : nums 변수를 set() 함수를 사용하여 반복 값을 제거하고, list() 함수를 사용하여 리스트로 변경한 것입니다.

 

if choice_p >= len(index_p):
    return len(index_p)
else:
    return choice_p

> if-else 문을 사용하여 선택할 수 있는 포켓몬의 수가 유일한 포켓몬의 수보다 같거나 크면 유일한 포켓몬의 수를 출력하고, 아니면 선택할 수 있는 포켓몬의 수를 출력하였습니다.

 

참고할 코드
def solution(ls):
    return min(len(ls)/2, len(set(ls)))

> 와우!!!

> 진짜 미쳤닼ㅋㅋㅋ

+ Recent posts