Problem Description

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.

Examples

Example 1:

Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.

Example 2:

Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.

Example 3:

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.

Constraints:

解析

給定一個字串 s ,

假設經過一個運算只看是英文字母的字元,且把所有大寫英文字元轉成小寫後變成 s’

要求寫一個演算法判斷 s 在經過以上轉換後是否是回文字串

一個字串 s 如果是回文, 代表 i = 0..(n/2-1)

s[i] = s[n-1-i], where n = len(s)