文字列 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