[프로그래머스, 159994] 카드 뭉치 (java)
Problem Solving/Programmers

[프로그래머스, 159994] 카드 뭉치 (java)

728x90

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

728x90

메모리: 81.3 MB, 시간: 0.04 ms

사용 알고리즘: 구현

class Solution {
    public String solution(String[] cards1, String[] cards2, String[] goal) {
        
        // 카드 뭉치를 가리키는 인덱스
        int idx1 = 0, idx2 = 0;
        
        for(int i = 0; i < goal.length; i++) {
            if(idx1 < cards1.length &&
                goal[i].equals(cards1[idx1])) idx1++;
            else if(idx2 < cards2.length &&
                        goal[i].equals(cards2[idx2])) idx2++;
            else return "No";
        }
        
        return "Yes";
    }
}
728x90