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.
For the purpose of this problem, we define empty string as valid palindrome.
簡單題,輸入一個字符串,不考慮數字、字母以外的任何符號。
判斷是否是回文串輸出即可。
設置雙指針查詢即可。
public class Solution { public boolean isPalindrome(String s) { s=s.toLowerCase(); int len = s.length() -1; if(len==-1) return true; for(int i=0,j=len;i<=j;i++,j--){ for(;!((s.charAt(i)>='0'&&s.charAt(i)<='9')||(s.charAt(i)>='a'&&s.charAt(i)<='z'))&&i='0'&&s.charAt(j)<='9')||(s.charAt(j)>='a'&&s.charAt(j)<='z'))&&i