Reverse digits of an integer.
Example1: x = 123, return 321Example2: x = -123, return -321
overflow!
public class Solution {
public int reverse(
int x)
{
int y=0
;
while(x!=0
)
{
//if(y*10/10!=y) return 0;
if (y > Integer.MAX_VALUE/10
)
return 0
;
if (y < Integer.MIN_VALUE/10
)
return 0
;
y=y*10+x
;
x/=10
;
}
return y;
}
}
转载于:https://www.cnblogs.com/hygeia/p/4970895.html
相关资源:JAVA上百实例源码以及开源项目