[LeetCode]Reverse Integer

来源:互联网 发布:java报表技术 编辑:程序博客网 时间:2024/04/29 02:23
class Solution {public:int reverse(int x) {// Start typing your C/C++ solution below// DO NOT write int main() functionint sign = 1;if(x < 0) sign = -1;unsigned int num = x < 0 ? -x : x;int ans = 0;while (num != 0){ans = ans*10 + num%10;num /= 10;}return ans*sign;}};