-
프로그래머스(Programmers) LEVEL2 - 위장Algorithm/Problems_Solving 2022. 10. 2. 12:39
def solution(clothes): dic= dict() for cloth in range(len(clothes)): if clothes[cloth][1] not in dic: dic[clothes[cloth][1]] = [clothes[cloth][0]] else: dic[clothes[cloth][1]].append(clothes[cloth][0]) val = len([item for values in dic.values() for item in values]) mul = 1 for v in dic.values(): mul = mul * len(v) if len(dic.keys()) == 1: return val else: return mul + val 정확성: 28.6 합계: 28.6 / 100.0
def solution(clothes): dic= dict() for cloth in range(len(clothes)): if clothes[cloth][1] not in dic: dic[clothes[cloth][1]] = 1 else: dic[clothes[cloth][1]] += 1 items = list(dic.values()) answer = 1 for item in items: answer = answer * (item + 1) # 각 item당 착용하지 않을 경우도 있기에 +1 answer -= 1 # 각 item을 모두 착용하지 않는것도( 위에서 계산되었기에 -1) return answer 정확성: 100.0 합계: 100.0 / 100.0
'Algorithm > Problems_Solving' 카테고리의 다른 글
프로그래머스(Programmers) LEVEL1 - 성격유형검사하기 (0) 2022.10.09 프로그래머스(Programmers) LEVEL2 - 전화번호 목록 (0) 2022.10.03 프로그래머스(Programmers) LEVEL2 - JadenCase 문자열 만들기 (0) 2022.10.02 프로그래머스(Programmers) LEVEL2 - 행렬의곱셈 (1) 2022.10.01 프로그래머스(Programmers) LEVEL2 - 최댓값과 최솟값 (0) 2022.10.01