class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param x int整型 
     * @return int整型
     */
    int reverse(int x) {
        // write code here
        string s;
        long long ans = 0;
        s = to_string(x);
        for(int i = s.size() -1;i >= 0;i--){
            if(s[i] == '-')
                ans *= -1;
            else 
                ans *= 10,ans += s[i] - '0';
        }
        if(ans == (int)ans)
            return ans;
        else 
            return 0;
    }
};