顿搜
飞过闲红千叶,夕岸在哪
类目归类
Reverse digits of an integer.
x = 123, return 321
x = -123, return -321
int reverse(int x) {
long long mResult = 0;
while (x) {
mResult = mResult * 10 + x % 10;
if (mResult > INT_MAX || mResult < INT_MIN) {
return 0;
}
x /= 10;
}
return mResult;
}#include<stdio.h>
#include<limits.h>
int reverse(int x) {
long long mResult = 0;
while (x) {
mResult = mResult * 10 + x % 10;
if (mResult > INT_MAX || mResult < INT_MIN) {
return 0;
}
x /= 10;
}
return mResult;
}
int main() {
printf("%d\n", reverse(1534236469));
system("pause");
return 0;
}