[LeetCode]#2108. Find First Palindromic String in the Array

Input: words = ["abc","car","ada","racecar","cool"]
Output: "ada"
Explanation: The first string that is palindromic is "ada".
Note that "racecar" is also palindromic, but it is not the first.
  1. Reverse input string
  2. If string == reversed string, return it.
  3. If no string and reversed string is equal, return ‘’
class Solution:
def firstPalindrome(self, words):
for i in words:
if i==i[::-1]:
return i
return ''

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Mindset of an Automated Tester [Automated Testing + CICD Series]

Learning C++: 5 Variable Declaration and Initialization Problems with Annotated Solutions

Why developers adore Agile Software Development? | Valiantsystems

Open Source IAM myths!

Setup Vultr Object Storage with AWS SDK v2 and Golang

Working with Item Groups in OpenHAB 3

Test Automation— Our challenges and how to overcome them

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

[LeetCode]#2124. Check if All A’s Appears Before All B’s

LeetCode Patterns Adventure 7 — Maximum Subarray

Python TreeMap

[LeetCode]#2053. Kth Distinct String in an Array