bit가 눈 앞에서 왔다갔다

Py) 72411 메뉴 리뉴얼 본문

Algorithm/Prob

Py) 72411 메뉴 리뉴얼

헬린인형 2022. 7. 7. 00:50

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

배가 너무 아프다.. 장기가 뜯어져나갈거 같은 느낌이 이런걸까

 

1차 시도: 62분

 

1. 김예고리즘

1-1. 알고리즘

1) 사용되는 알파벳을 list 하나에 정리
2) itertools의 combinations를 이용해 조합리스트를 만들고 orders의 원소마다 조합리스트의 원소가 부합하는게 있는지 찾아야 겠다고 생각

1-2. 코드 -> 틀림

from itertools import combinations
def solution(orders, course):
    answer = []
    alpha = []
    for check in orders:    # 종류별로 리스트 정리
        for i in check:
            if i not in alpha:
                alpha.append(i)


    for c in course:
        comb = list(combinations(alpha, c))     # 조합 리스트
        for ccheck in comb:     # 조합 리스트에서 원소 하나씩
            tmp = 0
            for o in orders:
                print(o.find(str(ccheck)))
                if o.find(str(ccheck)):       # 찾을문자가 있었던 경우
                    tmp += 1
                if tmp >= 2:
                    answer.append("".join(ccheck))

    return sorted(set(answer))

 

현재까지 찾은 틀린 이유:

print(o.find(str(ccheck)))

에서 찾을게 있으면 -1, 없으면 0을 리턴한다고 생각하고 있었음. -> find함수에 대해 잘못 알고 있었다. 

 

2. Solutions

https://unie2.tistory.com/1101?category=935213 참고해서 내일..

 

반응형
Comments