#2108
Easy Algorithms Find first palindromic string in the array
Array Two Pointers String
84.0% acceptance
Feb 25, 2026
1644
60
Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".
A string is palindromic if it reads the same forward and backward.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn first_palindrome(words: Vec<String>) -> String {
for w in &words {
let b = w.as_bytes();
if b.iter().zip(b.iter().rev()).all(|(a, c)| a == c) {
return w.clone();
}
}
String::new()
}
}