问题:如 123———>321       -123————>-321    120————>21 怎么玩呢?

注意要考虑整数的范围是-231次方到231-1

public int reverse(int x) {
int rev = 0;
while (x != 0) {
int pop = x % 10;
x /= 10;
if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0;
if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0;
rev = rev * 10 + pop;
}
return rev;
}

想要玩更多的?请到 https://leetcode.com/explore/

相关文章:

  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-27
  • 2022-01-06
  • 2021-08-25
  • 2021-06-13
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案