Skip to content

Commit 4b7e10d

Browse files
authored
Update find-first-palindromic-string-in-the-array.py
1 parent 02bbfbf commit 4b7e10d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Python/find-first-palindromic-string-in-the-array.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ def is_palindrome(s):
2020
if is_palindrome(w):
2121
return w
2222
return ""
23+
24+
25+
# Time: O(n)
26+
# Space: O(l), l is the max length of words
27+
class Solution2(object):
28+
def firstPalindrome(self, words):
29+
"""
30+
:type words: List[str]
31+
:rtype: str
32+
"""
33+
return next((x for x in words if x == x[::-1]), "")

0 commit comments

Comments
 (0)