https://school.programmers.co.kr/learn/courses/30/lessons/155652
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 알파벳 소문자 a - z로 이루어진 리스트를 생성한다.
2. skip에 저장된 알파벳들은 앞서 정의한 리스트에서 제외한다.
3. 재정의된 알파벳 리스트를 이용하여 문자를 변경한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import java.util.ArrayList;
class Solution {
public String solution(String s, String skip, int index) {
ArrayList<Character> list = new ArrayList<>();
for(char ch = 'a'; ch <= 'z'; ch++) {
list.add(ch);
}
for(int i = 0; i < skip.length(); i++) {
int idx = list.indexOf(skip.charAt(i));
list.remove(idx);
}
String answer = "";
for(int i = 0; i<s.length(); i++) {
char ch = s.charAt(i);
int idx1 = (list.indexOf(ch) + index) % list.size();
answer += String.valueOf(list.get(idx1));
}
return answer;
}
}
|
cs |
'Programmers > Lv.1' 카테고리의 다른 글
프로그래머스 Lv.1 - 소수 찾기 (0) | 2023.09.16 |
---|---|
프로그래머스 Lv.1 - 기사단원의 무기 (0) | 2023.09.16 |
프로그래머스 Lv.1 - 바탕화면정리 (0) | 2023.07.23 |
프로그래머스 Lv.1 - 크기가 작은 부분 문자열 (0) | 2023.05.31 |
프로그래머스 Lv.1 - 과일 장수 (0) | 2023.05.26 |