Skip to content

Instantly share code, notes, and snippets.

@cg4jins
Created August 19, 2019 01:27
Show Gist options
  • Save cg4jins/a1f4d772c9eac225552d932f8fbd94ad to your computer and use it in GitHub Desktop.
Save cg4jins/a1f4d772c9eac225552d932f8fbd94ad to your computer and use it in GitHub Desktop.
class Solution {
fun solution(s: String, n: Int): String {
return s.toCharArray().map { map(it, n) }.joinToString("")
}
private fun map(s: Char, n: Int): Char {
val ch = s.toInt()
if (ch in 65..90){
return if (ch + n in 65..90){
(ch+n).toChar()
}else{
(ch+n-26).toChar()
}
}
if (ch in 97..122){
return if (ch + n in 97..122){
(ch+n).toChar()
}else{
(ch+n-26).toChar()
}
}
return ' '
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment