牛客题霸--反转数字
反转数字
http://www.nowcoder.com/questionTerminal/1a3de8b83d12437aa05694b90e02f47a
如果是负数, 打上标记, 再把数字转换成字符串, 反转, 再转换成整数
class Solution { public: int reverse(int x) { int f = 0; if ( x < 0) { x = -x; f = 1; } string str = to_string(x); string s; for ( int i = str.size()-1; i >= 0; i--) s.push_back(str[i]); int xx = stoi(s); if ( f == 1) return -xx; return xx; } };