aboutsummaryrefslogtreecommitdiff
path: root/palindrome_number.rs
blob: bd3c641605c0e88f06fab1d116d29ea7646811e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
struct Solution;

impl Solution {
    fn is_palindrome(mut x: i32) -> bool {
        if x < 0 {
            return false;
        }
        let mut nums = Vec::with_capacity(10);
        while x != 0 {
            nums.push(x % 10);
            x /= 10;
        }
        for i in 0..(nums.len() / 2) {
            if nums[i] != nums[nums.len() - i - 1] {
                return false;
            }
        }
        true
    }
}

fn main() {
    print!("{}", Solution::is_palindrome(121));
}