Reverse 3-digit Integer

题目:

Reverse a 3-digit integer.

分析:

解法:

class Solution {
    /*
     * param number: A 3-digit number.
     * return: Reversed number.
     */
    public int reverseInteger(int number) {
        // write your code here
        int res = 0;
        while (number != 0) {
            int temp = number % 10;
            number /= 10;
            res = res * 10 + temp;
        }
        return res;
    }
};

results matching ""

    No results matching ""