public int solution(String skill, String[] skillTrees) {
int answer = 0;
for (String skillTree : skillTrees) {
if (isSkillValid(skill, skillTree)) {
answer++;
}
}
return answer;
}
private boolean isSkillValid(String skill, String skillTree) {
StringBuilder filteredSkillTree = new StringBuilder();
for (char c : skillTree.toCharArray()) {
if (skill.contains(Character.toString(c))) {
filteredSkillTree.append(c);
}
}
return skill.startsWith(filteredSkillTree.toString());
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/49993