Created
August 19, 2019 01:27
-
-
Save cg4jins/a1f4d772c9eac225552d932f8fbd94ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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