[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค-Lv1] ํฐ์ผ“๋ชฌ / Python

๐Ÿ“š Problem Solving/Programmers

https://programmers.co.kr/learn/courses/30/lessons/1845

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํฐ์ผ“๋ชฌ

๋‹น์‹ ์€ ํฐ์ผ“๋ชฌ์„ ์žก๊ธฐ ์œ„ํ•œ ์˜ค๋žœ ์—ฌํ–‰ ๋์—, ํ™ ๋ฐ•์‚ฌ๋‹˜์˜ ์—ฐ๊ตฌ์‹ค์— ๋„์ฐฉํ–ˆ์Šต๋‹ˆ๋‹ค. ํ™ ๋ฐ•์‚ฌ๋‹˜์€ ๋‹น์‹ ์—๊ฒŒ ์ž์‹ ์˜ ์—ฐ๊ตฌ์‹ค์— ์žˆ๋Š” ์ด N ๋งˆ๋ฆฌ์˜ ํฐ์ผ“๋ชฌ ์ค‘์—์„œ N/2๋งˆ๋ฆฌ๋ฅผ ๊ฐ€์ ธ๊ฐ€๋„ ์ข‹๋‹ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค.

programmers.co.kr

import sys
from itertools import combinations

input = sys.stdin.readline
nums = list(map(int, input().split()))


def solution(nums):
    n = len(nums) // 2
    nums = list(set(nums))
    if len(nums) > n:
        return n
    else:
        return len(nums)


print(solution(nums))

 

ํ•ด์„ค

์ฒ˜์Œ์—” ์•„๋ฌด ์ƒ๊ฐ์—†์ด combination์„ ์ด์šฉํ•ด ํ’€์—ˆ๋Š”๋ฐ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๊ฑธ๋ ธ๋‹ค..

set๋งŒ ์ด์šฉํ•ด์„œ ๊ฐ„๋‹จํžˆ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์˜€๋Š”๋ฐ... ํ—ˆ๋ฌดํ•˜๋‹ค..๐Ÿ˜ฅ