字符串2-整数反转

题目网址:https://leetcode.cn/leetbook/read/top-interview-questions-easy/xnx13t/

public class Solution {
    public int Reverse(int x) {
        int xx=0,k=1;
        int _x = x;
        while (x != 0)
        {
            k = x % 10;
            xx = 10 * xx + k;
            x /= 10;
        }
        if (xx > 0 && _x < 0) return 0;
        if(xx<0 && _x> 0) return 0;
        if(xx> 1000000000 || xx < -1000000000)
        {
            if(_x/ 1000000000 == xx % 10)
            {
                return xx;
            }
            else
            {
                return 0;
            }
        }
        return xx;
    }
}

 这道题用了点取巧的办法进行暴力破解,等以后再来详细研究。

猜你喜欢

转载自blog.csdn.net/oyqho/article/details/130027182
今日推荐