string 2 - integer reverse

Question website: 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;
    }
}

 This question uses a tricky method to crack it violently, and I will study it in detail later.

Guess you like

Origin blog.csdn.net/oyqho/article/details/130027182