mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
feat(solutions): add is-palindrome/rust/function
This commit is contained in:
14
challenges/is-palindrome/solutions/rust/function/src/main.rs
Normal file
14
challenges/is-palindrome/solutions/rust/function/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let mut string = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut string)
|
||||
.expect("Failed to read `stdin` line.");
|
||||
let string = string.trim().replace(" ", "").to_lowercase();
|
||||
let mut reverse: Vec<char> = string.chars().collect();
|
||||
reverse.reverse();
|
||||
let reverse: String = reverse.into_iter().collect();
|
||||
let is_palindrome = reverse == string;
|
||||
println!("{is_palindrome}");
|
||||
}
|
Reference in New Issue
Block a user