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.
Original question link: https://oj.leetcode.com/problems/valid-palindrome/
Question: If a string is given and whether it is a return string, only letters and numbers are considered.
Idea: Filter non-alphanumeric characters in the source string to form a new string and judge the new string.
Public static Boolean ispalindrome (string s) {If (S. isempty () return true; // filter character stringbuffer Buf = new stringbuffer (); For (INT I = 0; I <S. length (); I ++) {If (character. isletterordigit (S. charat (I) BUF. append (S. charat (I);} string TMP = Buf. tostring (). tolowercase (); For (INT I = 0; I <TMP. length (); I ++) {If (TMP. charat (I )! = TMP. charat (TMP. Length ()-I-1) return false;} return true ;}