forked from kelvins/algorithms-and-data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindromo.rs
More file actions
17 lines (17 loc) · 693 Bytes
/
palindromo.rs
File metadata and controls
17 lines (17 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
println!("{:?}", palindromo("".to_string()));
println!("{:?}", palindromo("a".to_string()));
println!("{:?}", palindromo("abba".to_string()));
println!("{:?}", palindromo("abbas".to_string()));
println!("{:?}", palindromo("tattarrattat".to_string()));
println!("{:?}", palindromo("Was it a palindrome?".to_string()));
println!("{:?}", palindromo("No lemon, no melon".to_string()));
}
fn palindromo(mut word: String) -> bool {
word = word.to_lowercase().split_whitespace().collect::<String>();
let reversed_string: String = word.chars().rev().collect::<String>();
if word.len() <= 1 {
return true;
}
word == reversed_string
}