알고리즘
프로그래머스 둘만의 암호 (JAVA)
박카스마시며코딩
2023. 4. 15. 14:58
https://school.programmers.co.kr/learn/courses/30/lessons/155652
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import java.util.*;
class Solution {
private static final int SIZE = 26;
public String solution(String s, String skip, int index) {
String answer = "";
Set<Character> skipAlpha = new HashSet<>();
for(int i = 0 ; i < skip.length() ; i++){
char ch = skip.charAt(i);
skipAlpha.add(ch);
}
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < s.length() ; i++){
char ch = s.charAt(i);
char next = jump(ch,index,skipAlpha);
sb.append(next);
}
answer = sb.toString();
return answer;
}
private static char jump(char ch, int index, Set<Character> skipAlpha){
while(index > 0){
ch++;
if(ch >'z'){
ch = 'a';
}
if(skipAlpha.contains(ch)){
continue;
}
index--;
}
return ch;
}
}