import java.util.*;
public class Solution {
/**
*
* @param x int整型
* @return int整型
*/
public int reverse (int x) {
// write code here
int wei=x;
int num=0;
while(wei!=0){
num++;
wei=wei/10;
}
int a[]=new int[num];
int i=0;
int flag=0;
if(x<0)flag=1;
while(x!=0)
{
a[i]=x%10;
i++;
x/=10;
}
int sum=0;
for(int j=0;j<a.length;j++)
{
sum+=a[j]*Math.pow(10,a.length-j-1);
}
//if(flag==1)sum=(-sum);
if(sum<-Math.pow(2,31)||sum>Math.pow(2,31)-1)return 0;
return sum;
}
}


京公网安备 11010502036488号