diff --git a/rs/find-first-palindromic-string-in-the-array.rs b/rs/find-first-palindromic-string-in-the-array.rs new file mode 100644 index 0000000..2dd7bb9 --- /dev/null +++ b/rs/find-first-palindromic-string-in-the-array.rs @@ -0,0 +1,14 @@ +impl Solution { + fn is_palindrome(word: &str) -> bool { + word.chars() + .take(word.len() >> 1) + .eq(word.chars().rev().take(word.len() >> 1)) + } + + pub fn first_palindrome(words: Vec) -> String { + words + .into_iter() + .find(|s| Self::is_palindrome(s)) + .unwrap_or(String::from("")) + } +}