[프로그래머스] Level.2 Summer/Winter Coding-스킬트리
2021. 1. 10. 16:05ㆍAlgorithm/프로그래머스
코딩테스트 연습 - 스킬트리
programmers.co.kr
억울하다 억울해!!!!!!!!!!!!!!!!!!
테스트 케이스 14번이 계속 틀렸다
분명 제한조건에 skill의 길이는 2이상이라 해서 skill의 길이가 1일때는 따로 생각해주지 않았는데
skill길이가 1일때 처리를 따로 해주니 바로 통과했다.....
#include <string>
#include<iostream>
#include <vector>
using namespace std;
int solution(string skill, vector<string> skill_trees) {
int answer = 0;
for(int i=0;i<skill_trees.size();i++){
vector<int>cache;
for(int j=0;j<skill.size();j++){
int idx=skill_trees[i].find(skill[j]);
cache.push_back(idx);
}
int before=cache[0];
for(int k=1;k<cache.size();k++){
if(before==-1&&cache[k]!=-1) break;
if(before>cache[k]&&cache[k]!=-1) break;
before=cache[k];
if(k==cache.size()-1) answer++;
}
if(cache.size()==1) answer++;
}
return answer;
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Level.2 GROUP BY-고양이와 개는 몇마리 있을까 (0) | 2021.01.11 |
---|---|
[프로그래머스] Level.2 스택/큐-프린터 (0) | 2021.01.10 |
[프로그래머스]Level.2 SUM.MAX.MIN-중복제거하기 (0) | 2021.01.09 |
[프로그래머스]Level.2 SUM.MAX.MIN-동물 수 구하기 (0) | 2021.01.09 |
[프로그래머스]Level.2 SUM,MAX,MIN-최솟값 구하기 (0) | 2021.01.09 |