Valid Palindrome (LeetCode 125)

Same as above (ignore case/punctuation).

Input Format

One line string s.

Output Format

"true" or "false".

Constraints

  • 0 <= len(s) <= 10^5.

Examples

Example 1:

Input:

0 = "A"
1 = " "
2 = "m"
3 = "a"
4 = "n"
5 = ","
6 = " "
7 = "a"
8 = " "
9 = "p"
10 = "l"
11 = "a"
12 = "n"
13 = ","
14 = " "
15 = "a"
16 = " "
17 = "c"
18 = "a"
19 = "n"
20 = "a"
21 = "l"
22 = ":"
23 = " "
24 = "P"
25 = "a"
26 = "n"
27 = "a"
28 = "m"
29 = "a"

Output:

true

Explanation:

Classic palindrome ignoring spaces/punctuation

Example 2:

Input:

0 = "r"
1 = "a"
2 = "c"
3 = "e"
4 = " "
5 = "a"
6 = " "
7 = "c"
8 = "a"
9 = "r"

Output:

false

Explanation:

Not a palindrome

Example 3:

Input:

0 = " "

Output:

true

Explanation:

Single space — only non-alphanumeric chars, empty after filter

Loading...
Valid Palindrome (LeetCode 125) - Strings