Files
cpp-flashcards/org/study_deck_02/dsa/two-pointers/0125-valid-palindrome.org
T

66 lines
1.3 KiB
Org Mode
Raw Normal View History

#+PROPERTY: STUDY_DECK_02
* TODO 0125. Valid Palindrome :easy:
:PROPERTIES:
:NEETCODE: [[file:../../roadmap.org::*0125. Valid Palindrome][0125. Valid Palindrome]]
:END:
A phrase is a *palindrome* 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.
Given a string ~s~, return ~true~/ if it is a *palindrome*, or /~false~/ otherwise/.
*Example 1:*
#+begin_src
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
#+end_src
*Example 2:*
#+begin_src
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
#+end_src
*Example 3:*
#+begin_src
Input: s = " "
Output: true
Explanation: s is an empty string "" after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.
#+end_src
*Constraints:*
- ~1 <= s.length <= 2 * 10^{5}~
- ~s~ consists only of printable ASCII characters.
** TODO Approach
Write your approach here.
** TODO Python
#+begin_src python
class Solution:
def isPalindrome(self, s: str) -> bool:
#+end_src
** TODO C++
#+begin_src cpp
class Solution {
public:
bool isPalindrome(string s) {
}
};
#+end_src