https://school.programmers.co.kr/learn/courses/30/lessons/159994
import java.util.*;
class Solution {
public String solution(String[] cards1, String[] cards2, String[] goal) {
ArrayList<String> c1List = new ArrayList<>(Arrays.asList(cards1));
ArrayList<String> c2List = new ArrayList<>(Arrays.asList(cards2));
for(int i=0; i<goal.length; i++) {
if(c1List.size()>0 && goal[i].equals(c1List.get(0))) {
c1List.remove(0);
if (i==goal.length-1) break;
} else if(c2List.size()>0 && goal[i].equals(c2List.get(0))) {
c2List.remove(0);
if (i==goal.length-1) break;
} else return "No";
}
return "Yes";
}
}
cards1 or cards2 가장 앞에 와있는 문자와 goal배열을 순서대로 비교하면서 같은게 있다면 제거해주고 또 가장 앞에 있는 문자와 비교해주는 방식을 계속 반복하기 위해 cards1과 cards2를 리스트에 넣어줘서 이용했다
큐를 빨리 익혀서 큐로도 풀어보고싶다
'코딩테스트-알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스/Lv.0] 정수를 나선형으로 배치하기 (1) | 2024.01.11 |
---|---|
[프로그래머스/Lv.1] 덧칠하기 (1) | 2024.01.09 |
[프로그래머스/Lv.1] 과일 장수 (0) | 2023.12.25 |
[프로그래머스/Lv.1] 명예의 전당 (1) (2) | 2023.12.22 |
[프로그래머스/Lv.1] 콜라 문제 (0) | 2023.12.22 |