//给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。
class Solution { public int reverse(int x) { if(x<0){ long a =-(long)x; System.out.print(a); String str = String.valueOf(a); String reverse = new StringBuffer(str).reverse().toString(); long i = Long.parseLong(reverse); if(i<(Math.pow(2,31)-1)&&i>(Math.pow(-2,31))){ return -(int)i; } return 0; }else if(x==0){ return 0; }else{ String str = String.valueOf(x); String reverse = new StringBuffer(str).reverse().toString(); long i = Long.parseLong(reverse); if(i<(Math.pow(2,31)-1)&&i>(Math.pow(-2,31))){ return (int)i; } return 0; } } }
原文:https://www.cnblogs.com/listenerxx/p/14127408.html