leetcode [#125] | GCidea's blog
目录

题目
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
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.For the purpose of this problem, we define empty string as valid palindrome.
解决方案
1 | public class Solution { |
注意事项
- 先处理特殊情况,字符串为空或者长度为零。
- 定义一个函数isDigitOrLetter()来判断某个字符是否是字母大小写+数字。
- 使用两个StringBuilder,分别从首尾遍历字符串,存储为字母大小写+数字的字符。
- 比较两个StringBuilder中内容是否一样即可。