230610 스킬트리

Jongleee·2023년 6월 10일
0

TIL

목록 보기
282/737
public int solution(String skill, String[] skillTrees) {
	int answer = 0;
	for (String skillTree : skillTrees) {
		StringBuilder filteredSkillTree = filterSkillTree(skill, skillTree);
		if (isSkillValid(skill, filteredSkillTree))
			answer++;
	}
	return answer;
}

private StringBuilder filterSkillTree(String skill, String skillTree) {
	StringBuilder filteredSkillTree = new StringBuilder();
	for (char c : skillTree.toCharArray()) {
		if (skill.contains(Character.toString(c))) {
			filteredSkillTree.append(c);
		}
	}
	return filteredSkillTree;
}

private boolean isSkillValid(String skill, StringBuilder filteredSkillTree) {
	return skill.indexOf(filteredSkillTree.toString()) == 0;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/49993

0개의 댓글