[문제]
https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr
[풀이]
- 각 의상별 가짓수 계산
- 부위별 옷에서 아무것도 안입는 경우가 있을 수 있어 각 가짓수에 1을 더해 곱한다.
- 하루에 최소 한 개의 옷은 입기 때문에 모두 안입은 경우인 1을 뺀다.
[코드]
def solution(clothes):
closet = {}
for cloth in clothes:
if cloth[1] in closet:
closet[cloth[1]] += 1
else:
closet[cloth[1]] = 1
answer = 1
for i in closet.values():
answer *= (i + 1)
return answer - 1
'문제풀이 > Programmers' 카테고리의 다른 글
[프로그래머스][Lv2][Python] JadenCase 문자열 만들기 (0) | 2022.09.19 |
---|---|
[프로그래머스][Lv2][Python] 최댓값과 최솟값 (1) | 2022.09.19 |
[프로그래머스][Lv2][Python] 행렬 테두리 회전하기 (0) | 2022.02.27 |
[프로그래머스][Lv1][Python] 로또의 최고 순위와 최저 순위 (0) | 2022.02.18 |
[프로그래머스][Lv1][Python] 소수 만들기 (0) | 2022.02.18 |
[문제]
https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr
[풀이]
- 각 의상별 가짓수 계산
- 부위별 옷에서 아무것도 안입는 경우가 있을 수 있어 각 가짓수에 1을 더해 곱한다.
- 하루에 최소 한 개의 옷은 입기 때문에 모두 안입은 경우인 1을 뺀다.
[코드]
def solution(clothes):
closet = {}
for cloth in clothes:
if cloth[1] in closet:
closet[cloth[1]] += 1
else:
closet[cloth[1]] = 1
answer = 1
for i in closet.values():
answer *= (i + 1)
return answer - 1
'문제풀이 > Programmers' 카테고리의 다른 글
[프로그래머스][Lv2][Python] JadenCase 문자열 만들기 (0) | 2022.09.19 |
---|---|
[프로그래머스][Lv2][Python] 최댓값과 최솟값 (1) | 2022.09.19 |
[프로그래머스][Lv2][Python] 행렬 테두리 회전하기 (0) | 2022.02.27 |
[프로그래머스][Lv1][Python] 로또의 최고 순위와 최저 순위 (0) | 2022.02.18 |
[프로그래머스][Lv1][Python] 소수 만들기 (0) | 2022.02.18 |