[해시] 위장 (Level 2)

정은경·2020년 3월 18일
0

문제


나의 풀이

def solution(clothes):
    temp = {}

    for i in clothes:
        print(i)
        if temp.get(i[1]):
            hoho = temp.get(i[1])
            hoho.append(i[0])
            temp[i[1]] = hoho
        else:
            temp[i[1]] = [i[0],]

    print(temp)

    nums = []
    for i in temp:
        nums.append(len(temp[i]))

    print(nums)
    hoho =1
    for i in nums:
        hoho *= (i+1) 
    hoho -= 1

    return hoho

남의 풀이

def solution(clothes):
    from collections import Counter
    from functools import reduce
    cnt = Counter([kind for name, kind in clothes])
    answer = reduce(lambda x, y: x*(y+1), cnt.values(), 1) - 1
    return answer
def solution(clothes):
    clothes_type = {}

    for c, t in clothes:
        if t not in clothes_type:
            clothes_type[t] = 2
        else:
            clothes_type[t] += 1

    cnt = 1
    for num in clothes_type.values():
        cnt *= num

    return cnt - 1
def solution(clothes):
    cl_dict = dict()
    for _ , categori in clothes:
        if categori in cl_dict:
            cl_dict[categori] += 1
        else:
            cl_dict[categori] = 2
    answer = 1
    for cate in cl_dict:
        answer *= cl_dict[cate]
    return answer - 1
def solution(clothes):
    answer = 1
    d = {}
    for e in clothes:
        d[e[-1]] = (len(e)-1) if e[-1] not in d else d[e[-1]] + (len(e)-1)
    for e in list(d.values()):
        answer *= (e+1)
    return answer-1
def solution(clothes):
    answer = 1
    aDict = {}
    for i in clothes:
        if i[1] in aDict:
            aDict[i[1]] += 1
        else:
            aDict[i[1]] = 1
    for i in aDict.keys():
        answer *= aDict[i] +1
    answer -= 1

    return answer
def solution(clothes):
    d = {}
    for v in clothes:
        if not v[1] in d:
            d[v[1]] = 1
        else:
            d[v[1]] += 1
    d = list(d.values())
    ans = 1
    for i in d:
        ans *= i+1
    return ans - 1
def solution(clothes):
    answer = {}
    for v,k in clothes:
        try:
            answer[k] += 1
        except KeyError:
            answer[k] = 2

    result = 1
    for i in answer.values():
        result *= i

    return result -1
from functools import reduce
from operator import mul

def solution(clothes):
    cDict = dict()

    for c in clothes:
        try:
            cDict[c[1]] += 1
        except:
            cDict[c[1]] = 2

    return reduce(mul, cDict.values()) - 1

느낀 점

  • 이것은 순열과 조합의 수학문제...!
profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글