mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 01:49:41 +01:00
15 lines
374 B
Rust
15 lines
374 B
Rust
|
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>) -> String {
|
||
|
words
|
||
|
.into_iter()
|
||
|
.find(|s| Self::is_palindrome(s))
|
||
|
.unwrap_or(String::from(""))
|
||
|
}
|
||
|
}
|