【每日一题】7. 整数反转

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

class Solution {
    public int reverse(int x) {
        int sum = 0;
        while(x != 0){
            int sum2 = sum * 10 + x % 10;
            x /= 10;
            if(sum2 / 10 != sum){
                return 0;
            }
            sum = sum2;
        }
        return sum;
    }
}
posted @ 2021-05-03 14:23  zjy4fun  阅读(50)  评论(0编辑  收藏  举报