[Python] 코딩테스트 연습 Lv1

NAYOUNG KIM·2023년 10월 13일
0

코딩테스트

목록 보기
7/13
post-thumbnail
# 1.3진법 뒤집기
def solution(n):
    answer = ''
    while (n>=1):
        rest = n % 3
        n = n // 3
        answer += str(rest)
    return int(answer, 3)

# 2.카드 뭉치
def solution(cards1, cards2, goal):
    for g in goal:
        if len(cards1) > 0 and g == cards1[0]:
            cards1.pop(0)       
        elif len(cards2) >0 and g == cards2[0]:
            cards2.pop(0)
        else:
            return "No"
    return "Yes"
    
# 3.추억 점수
def solution(name, yearning, photo):
    answer = []
    dic = dict(zip(name, yearning))    
    for pt in photo:
        score = 0
        for p in pt:
            if p in dic:
                score += dic[p]
        answer.append(score)
    return answer
    
# 4.삼총사
from itertools import combinations
def solution(number):
    comb = list(combinations(number, 3))
    answer = 0
    for cb in comb:
        if sum(cb) == 0:
            answer += 1
    return answer
    
# 5.최소직사각형
def solution(sizes):
    return max(max(x) for x in sizes) * max(min(x) for x in sizes)
profile
21세기 주인공

0개의 댓글