[LeetCode] Reverse Integer

暫時不考慮溢出的問題。

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


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