-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
💬 문제
[코딩테스트 연습 - 둘만의 암호](https://school.programmers.co.kr/learn/courses/30/lessons/155652)
💬 Idea
- abc 배열에서 건너뛸 문자들을 필터링한다
- s를 돌면서 abc 배열에서 해당 위치를 찾고, index를 더하여 idx를 도출한다
- idx가 abc의 카운트보다 클 수가 있으므로 해당 경우를 방지하기 위해 abc.count만큼 나눈 나머지를 index로 사용한다.
💬 풀이
func solution(_ s:String, _ skip:String, _ index:Int) -> String {
var abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"].filter{ !skip.contains($0) }
var ans = ""
for i in s {
ans += abc[(abc.firstIndex(of: String(i))! + index) % abc.count]
}
return ans
}