-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
💬 문제
[코딩테스트 연습 - 시저 암호](https://school.programmers.co.kr/learn/courses/30/lessons/12926)
💬 풀이
func solution(_ s:String, _ n:Int) -> String {
let alphabet = ["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"]
var result = ""
for i in s {
if i == " " {
result += " "
} else {
var idx = 0
for (index, j) in alphabet.enumerated() {
idx = i.lowercased() == j ? index : idx
}
idx = idx + n > 25 ? idx + n - 26 : idx + n
result += i.isUppercase ? alphabet[idx].uppercased() : alphabet[idx]
}
}
return result
}
소요시간
: 10분