Created
October 31, 2021 19:52
-
-
Save carolinemusyoka/5479c235174f7aeef90a71a2c50a86df to your computer and use it in GitHub Desktop.
This file contains hidden or 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 reverse(x: Int): Int { | |
var res = 0 | |
var n = x | |
while (n != 0) { | |
if (Math.abs(res) > Int.MAX_VALUE/10) return 0 | |
res = res*10 + n % 10 | |
n /= 10 | |
} | |
return res | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment