[PRO][Lv.1] 시저 암호

김정현·2023년 1월 13일
0

프로그래머스

목록 보기
36/50

📚 Problem

시저 암호

💫 Solve

func solution(_ s:String, _ n:Int) -> String {
    
    return s.utf8.map {
        var code = Int($0)
        switch code {
            case 65...90:
                code = (code + n - 65) % 26 + 65
            case 97...122:
                code = (code + n - 97) % 26 + 97
            default:
                break
        }
        return String(UnicodeScalar(code)!)
    }.joined()
}

🩺 Another Solution

깔게 없는 완벽한 코드~

profile
🍎💻👍

0개의 댓글