1. 程式人生 > >LintCode 37. 反轉一個3位整數

LintCode 37. 反轉一個3位整數

反轉一個只有3位數的整數。

public class Solution {
    /**
     * @param number: A 3-digit number.
     * @return: Reversed number.
     */
public int reverseInteger(int number) {
        // write your code here
int a = 0, b = 0, c = 0, reverse = 0;
a = number / 100;
b = (number - a * 100) / 10;
c = number - a * 100 - b * 10;
        if 
(c != 0) { reverse += c * 100; } if (b != 0) { reverse += b * 10; } if (a != 0) { reverse += a; } return reverse; } }