programmers- lv.1 (카드 뭉치)

이예송·2023년 7월 17일

PS

목록 보기
44/97

문제링크: 카드 뭉치

✍🏻 Information

content
언어python
난이도⭐️
풀이시간5분
제출횟수1
인터넷검색유무no




🍒 My Code

def solution(cards1, cards2, goal):
    one, two = 0, 0
    for i in range(len(goal)):
        if one<len(cards1) and cards1[one]==goal[i]:
            one+=1
        elif two<len(cards2) and cards2[two]==goal[i]:
            two+=1
        else:
            return "No"
    return "Yes"




💡 What I learned

  • index위치를 옮겨주는 것(나의풀이)뿐 아니라 stack의 pop을 사용하는 풀이도 있다.
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"

0개의 댓글