- 난이도: Lv1
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/159994
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/159994. 카드 뭉치
풀이 시간 : 12분
import java.util.*;
class Solution {
public String solution(String[] cards1, String[] cards2, String[] goal) {
String answer = "";
int card1Index = 0;
int card2Index = 0;
for(int i=0; i<goal.length; i++){
if(card1Index < cards1.length && goal[i].equals(cards1[card1Index])){
card1Index++;
answer = "Yes";
}
if(card2Index < cards2.length && goal[i].equals(cards2[card2Index])){
card2Index++;
answer = "Yes";
}
else {
answer = "No";
}
}
return answer;
}
}
//before
if(card2Index < cards2.length && goal[i].equals(cards2[card2Index])){
card2Index++;
answer = "Yes";
}
else {
answer = "No";
}
}
return answer;
//after
if(card1Index < cards1.length && goal[i].equals(cards1[card1Index])){
card1Index++;
answer = "Yes";
continue;
}
if(card2Index < cards2.length && goal[i].equals(cards2[card2Index])){
card2Index++;
answer = "Yes";
continue;
}
else {
answer = "No";
return answer;
}
}
return answer;
풀이 시간 : 16분(첫 풀이 시간 포함)
import java.util.*;
class Solution {
public String solution(String[] cards1, String[] cards2, String[] goal) {
String answer = "";
int card1Index = 0;
int card2Index = 0;
for(int i=0; i<goal.length; i++){
if(card1Index < cards1.length && goal[i].equals(cards1[card1Index])){
card1Index++;
answer = "Yes";
continue;
}
if(card2Index < cards2.length && goal[i].equals(cards2[card2Index])){
card2Index++;
answer = "Yes";
continue;
}
else {
answer = "No";
return answer;
}
}
return answer;
}
}