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.
思路:
1. 必须把字符串统一为小写,而且要忽略除数字和字符外的所有符号。
2. 利用 String.toCharArray() 转换字符串为Character数组。
3. 双指针check头尾,直到双指针相遇前停止,不相等则返回false。
4. 结束check则返回true。
No comments:
Post a Comment