Skip to content

Instantly share code, notes, and snippets.

@carolinemusyoka
Created October 31, 2021 19:52
Show Gist options
  • Save carolinemusyoka/5479c235174f7aeef90a71a2c50a86df to your computer and use it in GitHub Desktop.
Save carolinemusyoka/5479c235174f7aeef90a71a2c50a86df to your computer and use it in GitHub Desktop.
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