java.lang.Object
g2101_2200.s2108_find_first_palindromic_string_in_the_array.Solution

public class Solution extends Object
2108 - Find First Palindromic String in the Array.<p>Easy</p> <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>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;abc&rdquo;,&ldquo;car&rdquo;,&ldquo;ada&rdquo;,&ldquo;racecar&rdquo;,&ldquo;cool&rdquo;]</p> <p><strong>Output:</strong> &ldquo;ada&rdquo;</p> <p><strong>Explanation:</strong> The first string that is palindromic is &ldquo;ada&rdquo;. Note that &ldquo;racecar&rdquo; is also palindromic, but it is not the first.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;notapalindrome&rdquo;,&ldquo;racecar&rdquo;]</p> <p><strong>Output:</strong> &ldquo;racecar&rdquo;</p> <p><strong>Explanation:</strong> The first and only string that is palindromic is &ldquo;racecar&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> words = [&ldquo;def&rdquo;,&ldquo;ghi&rdquo;]</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> There are no palindromic strings, so the empty string is returned.</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>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isPalindrome

      public static boolean isPalindrome(String s)
    • firstPalindrome

      public String firstPalindrome(String[] words)