leetcode第七题Reverse Integer (java)

Reverse Integer

Reverse digits of an integer.

Example1: x = 123, return 321

Example2: x = -123, return -321

time=272ms accepted

public class Solution {
public int reverse(int x) {
long recv=0;
int mod=0;
int xabs=Math.abs(x);
while(xabs>0){
mod=xabs%10;
recv=recv*10+mod;
xabs/=10;
if(recv>(Math.pow(2, 31)-1))
return 0;
}
if(x<0)
recv=-recv; return (int)recv;
}
}
上一篇:Mac 下 Nginx、MySQL、PHP-FPM 的安装配置


下一篇:static wechat red package tool