leetcode 7 Reverse Integer

class Solution {
public:
    int reverse(int x) {
        int res = 0;
        while (x != 0) {
            int t = res * 10 + x % 10;
            if (t / 10 != res) return 0;
            res = t;
            x /= 10;
        }
        return res;
    }
};
posted @ 2017-01-30 23:54  王坤1993  阅读(156)  评论(0编辑  收藏  举报