LeetCode#125
思路
回文串最常见3种解法:双指针、栈、字符串反转
双指针
- PS:面试中不建议用正则,因为考察不出你的水平,面试官肯定还会问别的方法实现过滤
public static boolean isPalindrome2(String s) {
// 过滤非字母数字字符, \\W ==> [^a-zA-Z0-9],面试时用正则可能还会问另一种方法
String str = s.replaceAll("\\W", "");
// 双指针
int start = 0, end = str.length() - 1;
while (start < end) {
if (Character.toUpperCase(str.charAt(start)) != Character.toUpperCase(str.c