DHistory
[Programmers] Level 1 - 카드 뭉치 본문
문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
def solution(cards1, cards2, goal):
    # 초기화
    i = 0
    j = 0
    k = 0
    # 문제 풀이
    while True:
        # 종료 조건 1: Goal 완성 시 종료
        if k >= len(goal):
            return "Yes"
        
        current = goal[k]
        # 종료 조건 2: goal에 해당하는 card가 없는 경우 종료
        if cards1[i] != current and cards2[j] != current:
            return "No"
        if i < len(cards1) - 1 and cards1[i] == current:
            i += 1
        if j < len(cards2) - 1 and cards2[j] == current:
            j += 1
        k += 1
채점 결과

'Computer Science > Algorithm' 카테고리의 다른 글
| [Programmers] Level 1 - 개인정보 수집 유효기간 (0) | 2023.06.29 | 
|---|---|
| [Programmers] Level 1 - 둘만의 암호 (0) | 2023.06.28 | 
| [Programmers] Level 1 - 대충 만든 자판 (0) | 2023.06.15 | 
| [Programmers] Level 1 - 덧칠하기 (0) | 2023.06.15 | 
| [Programmers] Level 1 - 바탕화면 정리 (0) | 2023.06.12 |