알고리즘/프로그래머스
[Python] 위장
dding96
2022. 12. 7. 10:20
https://school.programmers.co.kr/learn/courses/30/lessons/42578
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
- 나의 풀이
def solution(clothes):
import math
clothes.sort(key = lambda x : x[1])
items = []
item = []
attribute = []
for i in clothes:
if item == []:
item.append(i[0])
attribute.append(i[1])
elif i[1] == attribute[-1]:
item.append(i[0])
else:
items.append(item)
item = []
item.append(i[0])
attribute.append(i[1])
items.append(item)
answer = 1
if len(items) > 1:
for i in items:
answer *= len(i)+1
answer -= 1
else:
answer = len(items[0])
- 다른 사람의 풀이
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