[Leetcode]-- Valid Palindrome

[Leetcode]-- Valid Palindrome
public class Solution {
    public boolean isPalindrome(String s) {
        if(s  == null || s.length() <2 ){
            return true;
        }
        
        String mystring = s.replaceAll("[^A-Za-z0-9]", "");
        mystring = mystring.toLowerCase();
        
        // 只需遍历前一半就可以了
        for(int i = 0 ; i< mystring.length()/2; i++){
            if(mystring.charAt(i) != mystring.charAt(mystring.length() - 1 - i)){
                return false;
            }
        }
        return true;
        
    }
}
[Leetcode]-- Valid Palindrome

[Leetcode]-- Valid Palindrome

上一篇:Leetcode Reverse Nodes in k-Group


下一篇:LeetCode: Container With Most Water