【leetCode】7_反转整数

class Solution {
    public int reverse(int x) {
        int y = 0;
        int ty = 0;
        int pn = x > 0? 1:-1;
        while (x != 0){
            ty = y;
            y *= 10;
            int t = x % 10;
            y += t;
            boolean b = false;
            if (t > 0 && y > 0 || t < 0 && y < 0){
                if (t > 0 && y < 0 || t < 0 && y > 0){
                    b = true;
                }
            }
            if (y / 10 != ty || b){
                return 0;
            }
            x = x / 10;
        }
        return y;
    }
}

 

你可能感兴趣的:(leetCode)