공부기록/프로그래머스

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

메델 2023. 10. 15. 19:10
import java.util.*;

class Solution {
    public String solution(String[] cards1, String[] cards2, String[] goal) {
        Queue<String> queue1 = new LinkedList<>();
        Queue<String> queue2 = new LinkedList<>();
        
        for(String x: cards1){
            queue1.add(x);
        }
        
        for(String x: cards2){
            queue2.add(x);
        }
        
        for(int i=0; i<goal.length; i++){
            
            String a = queue1.peek();
            String b = queue2.peek();
            
            if(a != null && a.equals(goal[i])){
                queue1.poll();
            }else if(b != null && b.equals(goal[i])){
                queue2.poll();
            }else{
                return "No";
            }
        }
 
        return "Yes";
    }
}