Created
May 11, 2024 14:38
-
-
Save d4vsanchez/5825d1f0244d253fcd401ceacf9e354e to your computer and use it in GitHub Desktop.
Solution for the "9. Palindrome Number" problem from LeetCode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl Solution { | |
pub fn is_palindrome(x: i32) -> bool { | |
if x < 0 { | |
return false; | |
} | |
let mut x_copy = x; | |
let mut reverse: i32 = 0; | |
while x_copy > 0 { | |
reverse = (reverse * 10) + (x_copy % 10); | |
x_copy = x_copy / 10; | |
} | |
reverse == x | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment