Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. object Solution {
  2.  
  3. def reverse(x: Int): Int = {
  4. var lastX = x
  5. var lastVal = 0
  6.  
  7. while (lastX != 0) {
  8. val pop = lastX % 10
  9. if (lastVal > Int.MaxValue / 10 || (lastVal == Int.MaxValue / 10 && pop > 7)) {
  10. return 0
  11. }
  12. if (lastVal < Int.MinValue / 10 || (lastVal == Int.MinValue / 10 && pop < -8)) {
  13. return 0
  14. }
  15. lastVal = lastVal * 10 + pop
  16. lastX /= 10
  17. }
  18. return lastVal
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement