palindrome-number

Runtime: 8 ms, faster than 46.98% of Rust online submissions for Palindrome Number.
Memory Usage: 2.3 MB, less than 100.00% of Rust online submissions for Palindrome Number.

    pub fn is_palindrome(x: i32) -> bool {
        let mut x = x;
        if x < 0 || (x % 10 == 0 && x != 0) {
            return false;
        }
        let mut reverse_number = 0;
        while x > reverse_number {
            reverse_number = reverse_number * 10 + x % 10;
            x = x / 10;
        }
        return x == reverse_number || x == reverse_number / 10;
    }

你可能感兴趣的:(palindrome-number)