题解 | #反转数字#
反转数字
http://www.nowcoder.com/practice/1a3de8b83d12437aa05694b90e02f47a
class Solution {
public:
/**
*
* @param x int整型
* @return int整型
*/
#define MAX_value 2147483647
#define MIN_value -2147483648
int reverse(int x) {
// write code here
long y=0;//存放翻转之后的数据(用int类型的会出错)
long x1=x;
while(x1!=0)
{
y=y*10+x1%10;
x1=x1/10;
}
if(y> MAX_value|| y< MIN_value)
return 0;
return (int)y;
}
};牛客刷题记录 文章被收录于专栏
记录自己的刷题记录,刷过的题的解法


