Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
<Solution>這題是在處理 palindrom,但和找 Longest Palindromic Substring 有幾點不一樣
- 不用算長度
- input 有非字母的字元,像是空白、逗號等
- 兩個 pointer,一個從前面開始,一個從後面開始
- 遇到不是字母數字,就不要處理
- 字母都轉成小寫再比對
- 一旦有不一樣的,就回傳 false
C++
Java
kotlin
沒有留言:
張貼留言