leetcode 7

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/luozhong11/article/details/64132031

public class Solution {
    public int reverse(int x)
    {
    
     int result = 0;
     while (x != 0)
     {
            int tail = x % 10;
            int newResult = result * 10 + tail;
            if ((newResult - tail) / 10 != result)
            { return 0; }
            result = newResult;
            x = x / 10;
        }

        return result;
    }
}



取模!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章