LeetCode 7 Reverse Integer int:2147483647-2147483648 难度:2

https://leetcode.com/problems/reverse-integer/

 

class Solution {
public:
    int inf = ~0u >> 1;
    int reverse(int x) {
        if(x == 0)return 0;
        long long tx = x;
        long long ans = 0;
        for(int i = 0;tx;i++){
            ans = ans * 10 + tx % 10;
            tx /= 10;
        }
        return int(ans) == ans?ans:0;
    }
};

  

posted @ 2015-09-01 18:06  雪溯  阅读(208)  评论(0编辑  收藏  举报