문제
https://school.programmers.co.kr/learn/courses/30/lessons/159994
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이와 코드
목표 단어가 두 뭉치의 카드 중 맨 앞의 단어일 경우만 "Yes"라고 생각하고 코딩했더니 정답!
#include <string>
#include <vector>
using namespace std;
string solution(vector<string> cards1, vector<string> cards2, vector<string> goal) {
int count1 = 0;
int count2 = 0;
for (int i=0; i<goal.size(); i++){
if (goal[i] == cards1[count1]){
count1++;
}else if (goal[i] == cards2[count2]){
count2++;
}else{
return "No";
}
}
return "Yes";
}
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 소수 찾기 (1) | 2023.11.02 |
---|---|
[프로그래머스] 과일 장수 (2) | 2023.11.02 |
[프로그래머스] 명예의 전당(1) (2) | 2023.10.26 |
[프로그래머스] 추억 점수 (2) | 2023.08.15 |
[프로그래머스] 콜라 문제 (1) | 2023.08.11 |