题解 | #反转数字#
反转数字
https://www.nowcoder.com/practice/1a3de8b83d12437aa05694b90e02f47a
#include <climits> class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param x int整型 * @return int整型 */ int reverse(int x) { // write code here bool flag = false; if(x < 0) flag = true; x = abs(x); // 结果需要一个大的数据范围 long int t = 0; while(x) { t = t * 10 + x % 10; x = x / 10; } if(flag) t = -t; if(t < INT_MIN || t > INT_MAX) return 0; return t; } };