import java.util.*;
class Solution {
public String solution(String s, String skip, int index) {
String answer = "";
char[] skipChArr = skip.toCharArray();
char[] sChArr = s.toCharArray();
var skipChIntSet = new HashSet<Integer>();
var chList = new ArrayList<Character>();
for(char ch : skipChArr) skipChIntSet.add((int)ch);
for(char ch : sChArr){
int chInt = (int)ch;
//index처리
for(int i=0; i<index; i++){
chInt++;
if(chInt > (int)('z')) chInt = (int)('a');
while(skipChIntSet.contains(chInt)){
chInt++;
if(chInt > (int)('z')) chInt = (int)('a');
}
}
chList.add((char)chInt);
}
char[] chArrTm = new char[chList.size()];
for(int i=0; i<chList.size(); i++) chArrTm[i] = chList.get(i);
answer = String.valueOf(chArrTm);
return answer;
}
}
def solution(s, skip, index):
answer, skipSet, reList, skipOrdSet = '', set(), [], set()
for ch in skip:
skipSet.add(ch)
skipOrdSet.add(ord(ch))
for ch in s:
newAs = ord(ch)
for i in range(index):
newAs += 1
if newAs > ord('z'):
newAs = ord('a')
while newAs in skipOrdSet:
newAs += 1
if newAs > ord('z'):
newAs = ord('a')
reList.append(chr(newAs))
answer = ''.join(reList)
return answer
'백준 & 프로그래머스' 카테고리의 다른 글
[프로그래머스] [2019 카카오 개발자 겨울 인턴십] 크레인 인형뽑기 게임 java (0) | 2024.02.02 |
---|---|
프로그래머스. 완주하지 못한 선수. Java and Python (0) | 2024.01.26 |
프로그래머스.교점에 별 만들기.Java and Python (0) | 2024.01.15 |
프로그래머스[2024 KAKAO WINTER INTERNSHIP]가장 많이 받은 선물.Java and Python (0) | 2024.01.10 |
뒤에 있는 큰 수 찾기 (0) | 2023.12.19 |
댓글