๐Ÿ—๏ธ Algorithm/โฌ› ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

โฌ› [Programmers] [Python] Level2_์œ„์žฅ

Dbswnstjd 2023. 4. 6. 10:41

๋ฌธ์ œ

https://school.programmers.co.kr/learn/courses/30/lessons/42578

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

ํ’€์ด

# ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - ์œ„์žฅ
def solution(clothes):
    answer = 1
    dic = {}
    for v, k in clothes:
        if not k in dic: # ์ฒ˜์Œ์ผ ๊ฒฝ์šฐ ๋”•์…”๋„ˆ๋ฆฌ ์ดˆ๊ธฐํ™”
            dic[k] = 0
        dic[k] += 1
    
    for v in dic.values():
        answer *= v + 1
    
    return answer - 1