LeetCode-7. Reverse Integer

Reverse digits of an integer.

Example1:

1
x = 123, return 321

Example2:

1
x = -123, return -321

Note:

The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

代码

1
2
3
4
5
6
7
8
9
10
public long reverse(int x){
long y=0;
int n;
while( x != 0){
n = x%10;
y = y*10 + n;
x /= 10;
}
return y;
}
-------------本文结束感谢您的阅读-------------
Thank you for your encouragement