2022-03-27 20:38:29 +08:00
< p > Given an array of strings < code > words< / code > , return < em > the first < strong > palindromic< / strong > string in the array< / em > . If there is no such string, return < em > an < strong > empty string< / strong > < / em > < code > " " < / code > .< / p >
< p > A string is < strong > palindromic< / strong > if it reads the same forward and backward.< / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:38:29 +08:00
< pre >
< strong > Input:< / strong > words = [" abc" ," car" ," ada" ," racecar" ," cool" ]
< strong > Output:< / strong > " ada"
< strong > Explanation:< / strong > The first string that is palindromic is " ada" .
Note that " racecar" is also palindromic, but it is not the first.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 20:38:29 +08:00
< pre >
< strong > Input:< / strong > words = [" notapalindrome" ," racecar" ]
< strong > Output:< / strong > " racecar"
< strong > Explanation:< / strong > The first and only string that is palindromic is " racecar" .
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 20:38:29 +08:00
< pre >
< strong > Input:< / strong > words = [" def" ," ghi" ]
< strong > Output:< / strong > " "
< strong > Explanation:< / strong > There are no palindromic strings, so the empty string is returned.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = words.length < = 100< / code > < / li >
< li > < code > 1 < = words[i].length < = 100< / code > < / li >
< li > < code > words[i]< / code > consists only of lowercase English letters.< / li >
< / ul >