https://school.programmers.co.kr/learn/courses/30/lessons/84512
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
알파벳의 조합 >> 완전 탐색으로 품(dfs)
import java.util.*;
class Solution {
public int cnt = 0;
public HashMap<String,Integer> map;
public int solution(String word) {
int answer = 0;
map = new HashMap<>();
dfs("",0);
answer = map.get(word);
return answer;
}
public void dfs(String word, int depth) {
map.put(word,cnt);
if(depth == 5) {
return;
}
for(int i = 0; i < 5; i++) {
cnt++;
dfs(word + change(i), depth + 1);
}
}
public String change(int n) {
if(n == 0) {
return "A";
}else if(n == 1) {
return "E";
}else if(n == 2) {
return "I";
}else if(n == 3) {
return "O";
}
return "U";
}
}
결과
'Backend > 알고리즘' 카테고리의 다른 글
[프로그래머스]Lv3. 네트워크 (1) | 2024.05.28 |
---|---|
[프로그래머스] Lv2. 주식가격 (0) | 2024.05.28 |
[프로그래머스] Lv.2 게임 맵 최단거리 (0) | 2024.05.28 |
[프로그래머스] Lv2. 타겟 넘버 (0) | 2024.05.18 |
[프로그래머스] Lv2. 전화번호 목록 (0) | 2024.05.18 |