Class Solution

java.lang.Object
g0101_0200.s0125_valid_palindrome.Solution

public class Solution extends Object
125 - Valid Palindrome.<p>Easy</p> <p>A phrase is a <strong>palindrome</strong> if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.</p> <p>Given a string <code>s</code>, return <code>true</code> <em>if it is a <strong>palindrome</strong> , or</em> <code>false</code> <em>otherwise</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;A man, a plan, a canal: Panama&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &ldquo;amanaplanacanalpanama&rdquo; is a palindrome.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;race a car&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> &ldquo;raceacar&rdquo; is not a palindrome.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &quot; &quot;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> s is an empty string &quot;&quot; after removing non-alphanumeric characters. Since an empty string reads the same forward and backward, it is a palindrome.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 2 * 10<sup>5</sup></code></li> <li><code>s</code> consists only of printable ASCII characters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isPalindrome

      public boolean isPalindrome(String s)