public int reverse(int x) {
        int result = 0;
        int measure = Integer.MAX_VALUE / 10;
        while(x != 0){
            if(Math.abs(result) > measure) return 0;
            result = result * 10 + x % 10;
            x /= 10;
        }
        return result;
    }