Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Solution {
- def reverse(x: Int): Int = {
- var lastX = x
- var lastVal = 0
- while (lastX != 0) {
- val pop = lastX % 10
- if (lastVal > Int.MaxValue / 10 || (lastVal == Int.MaxValue / 10 && pop > 7)) {
- return 0
- }
- if (lastVal < Int.MinValue / 10 || (lastVal == Int.MinValue / 10 && pop < -8)) {
- return 0
- }
- lastVal = lastVal * 10 + pop
- lastX /= 10
- }
- return lastVal
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement