JAVA

[프로그래머스] 카드뭉치 (Java)

데브킹덕 2024. 5. 8. 17:08

https://school.programmers.co.kr/learn/courses/30/lessons/159994?language=java

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public String solution(String[] cards1, String[] cards2, String[] goal) {
        
        int card1Index = 0;
        int card2Index = 0;
        
        for (var word: goal){
            if ((cards1.length != card1Index) && (word.equals(cards1[card1Index]))){
                 card1Index += 1;
             }
            else if ((cards2.length != card2Index) && (word.equals(cards2[card2Index]))){
                card2Index += 1;
            }
            else{
                return "No";
            }
            
        }
        
        return "Yes";
    }
}