Skip to content

Commit

Permalink
impl solution polindrome number
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze committed Oct 26, 2023
1 parent b8dfd07 commit bad8db9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
30 changes: 28 additions & 2 deletions leetcode/src/solutions/palindrome_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,33 @@ impl Solution for SolutionImpl {
}

impl SolutionImpl {
pub fn is_palindrome(x: i32) -> bool {
todo!()
pub fn is_palindrome(mut x: i32) -> bool {
if x < 0 {
false
} else if x < 10 {
true
} else {
let mut v = Vec::new();
while x > 0 {
let residue = x % 10;
x /= 10;

v.push(residue);
}

let mut start = 0;
let mut end = v.len() - 1;

while start < end {
if v[start] != v[end] {
return false;
}

start += 1;
end -= 1;
}

true
}
}
}
1 change: 1 addition & 0 deletions runtime/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn register_all(handle: ContainerHandle) -> anyhow::Result<()> {
handle.register_solution(|_| solutions::string_to_integer::SolutionImpl)?;

handle.register_problem(|_| problems::palindrome_number::ProblemImpl)?;
handle.register_solution(|_| solutions::palindrome_number::SolutionImpl)?;

Ok(())
}

0 comments on commit bad8db9

Please sign in to comment.