문제 링크

풀이 과정

전체 코드

def solution(cards1, cards2, goal):
    flag = True
    cards1_idx, cards2_idx, goal_idx = 0, 0, 0
    cards1_len, cards2_len, goal_len = tuple(
        map(lambda x: len(x), [cards1, cards2, goal])
    )
    
    while goal_idx < goal_len:
        if (cards1_idx < cards1_len) and (goal[goal_idx] == cards1[cards1_idx]):
            cards1_idx += 1
            goal_idx += 1
        elif (cards2_idx < cards2_len) and (goal[goal_idx] == cards2[cards2_idx]):
            cards2_idx += 1
            goal_idx += 1
        else:
            flag = False
            break
    
    return "Yes" if flag else "No"