125. Valid Palindrome
A phrase is a palindrome if it reads the same forwards and backwards after converting all uppercase letters to lowercase and removing all non-alphanumeric characters. Alphanumeric characters include letters and numbers.
If the string s is given, returns true if it is a palindrome, or false otherwise.
Example 1:
Input: s = "Man, Plan, Channel: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Example 2:
Input: s = "car race"
Output: false
Explanation: "raceacar" is not a palindrome.
Example 3:
Input: s = " "
Output: true
Explanation: s is the empty string "" after removing non-alphanumeric characters.
Since the empty string reads forwards and backwards the same way, it is a palindrome.
Limitations:
1 <= s.length <= 2 * 105
s consists of printable ASCII characters only.
Solution
class Solution {
public:
bool isPalindrome(string s) {
string words = "";
for(int i=0;i
Comments
Post a Comment