aboutsummaryrefslogtreecommitdiff
path: root/other/palindrome_number.rs
diff options
context:
space:
mode:
Diffstat (limited to 'other/palindrome_number.rs')
-rw-r--r--other/palindrome_number.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/other/palindrome_number.rs b/other/palindrome_number.rs
new file mode 100644
index 0000000..bd3c641
--- /dev/null
+++ b/other/palindrome_number.rs
@@ -0,0 +1,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));
+}