Skip to content

Instantly share code, notes, and snippets.

@d4vsanchez
Created May 11, 2024 14:38
Show Gist options
  • Save d4vsanchez/5825d1f0244d253fcd401ceacf9e354e to your computer and use it in GitHub Desktop.
Save d4vsanchez/5825d1f0244d253fcd401ceacf9e354e to your computer and use it in GitHub Desktop.
Solution for the "9. Palindrome Number" problem from LeetCode
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