GitHubSeob
C++ / 프로그래머스 / 카드 뭉치 본문
문제
https://school.programmers.co.kr/learn/courses/30/lessons/159994
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제풀이
goal 벡터를 기준으로 탐색하면서 cards1[idx1]과 같으면 ++idx1를,
cards2[idx2]와 같으면 ++idx2를,
둘 다 다르면 No를 return 한다.
for문이 종료되면 완성된 것이므로 Yes를 return 한다.
코드
#include <string>
#include <vector>
using namespace std;
string solution(vector<string> cards1, vector<string> cards2, vector<string> goal) {
int idx(0), idx1(0), idx2(0);
for (idx = 0; idx < goal.size(); ++idx) {
if (cards1[idx1] == goal[idx]) {
++idx1;
}
else if (cards2[idx2] == goal[idx]) {
++idx2;
}
else return "No";
}
return "Yes";
}
'Programmers > Level 1' 카테고리의 다른 글
C++ / 프로그래머스 / 명예의 전당 (1) (0) | 2023.06.24 |
---|---|
C++ / 프로그래머스 / 과일 장수 (0) | 2023.06.24 |
C++ / 프로그래머스 / 덧칠하기 (0) | 2023.06.24 |
C++ / 프로그래머스 / 기사단원의 무기 (0) | 2023.06.24 |
C++ / 프로그래머스 / 숫자 짝꿍 (0) | 2023.06.24 |