- 난이도: Lv1
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/155652
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/155652. 둘만의 암호
풀이 시간 : 12분
import java.util.*;
class Solution {
public String solution(String s, String skip, int index) {
String answer = "";
for(int i=0; i<s.length(); i++){
char changeS = s.charAt(i);
for(int j=0; j<index; j++){
changeS++;
if(changeS > 'z'){
//changeS = changeS - 26;
changeS -= 26;
}
}
answer += changeS;
}
return answer;
}
}
//before
for(int j=0; j<index; j++){
changeS++;
if(changeS > 'z'){
changeS -= 26;
}
}
answer += changeS;
//after
for(int j=0; j<index; j++){
changeS++;
if(changeS > 'z'){
changeS -= 26;
}
//skip
if(skip.contains(String.valueOf(changeS))){
j--;
}
}
answer += changeS;
풀이 시간 : 16분(첫 풀이 시간 포함)
import java.util.*;
class Solution {
public String solution(String s, String skip, int index) {
String answer = "";
for(int i=0; i<s.length(); i++){
char changeS = s.charAt(i);
for(int j=0; j<index; j++){
changeS++;
if(changeS > 'z'){
//changeS = changeS - 26;
changeS -= 26;
}
//skip
if(skip.contains(String.valueOf(changeS))){
j--;
}
}
answer += changeS;
}
return answer;
}
}