您的位置:首页 > 其它

LeetCode Reverse Integer

2015-11-01 23:42 330 查看
//考虑越界问题
#include<stdio.h>
int reverse(int x) {
if(x>0&&x>INT_MAX)return 0;
if(x<0&&(-x)>INT_MAX) return 0;
long res = 0;
while(x)
{
res = res*10 + x%10;
x /= 10;
}
if(res>0&&res>INT_MAX)return 0;
if(res<0&&(-res)>INT_MAX) return 0;
return res;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: