ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์œ„์žฅ

 

programmers.co.kr

 

๋ฌธ์ œ ํ’€์ด

์œ„์žฅ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌผ๊ฑด์˜ ๊ฐ€์ง€์ˆ˜์— ๋”ฐ๋ผ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. Counter๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์‰ฝ๊ฒŒ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

from collections import Counter


def solution(clothes):
    answer = 1
    kinds = Counter([kind for _, kind in clothes])
    nums = [x for x in kinds.values()]
    for num in nums:
        answer *= num + 1
    return answer - 1
  • ์ธ์ž๋กœ ์ฃผ์–ด์ง€๋Š” clothes ์—์„œ ์ข…๋ฅ˜๋ฅผ Counter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์นด์šดํŠธ ํ•œ๋‹ค.
  • ๋ฌผ๊ฑด์˜ ์ข…๋ฅ˜์— ๋”ฐ๋ผ (์ข…๋ฅ˜1 + 1) * (์ข…๋ฅ˜2 + 1) ... (์ข…๋ฅ˜N + 1) - 1 ๊ณผ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์œ„์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์กฐํ•ฉ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.
    • Counter์˜ ๋ฐ˜ํ™˜ ๊ฐ’์€ dictionary์ด๋‹ค.
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€