415

来源:互联网 发布:软件架构师程序员 编辑:程序博客网 时间:2024/05/22 04:26

4.14

public class Solution {    /**     * @param s A string     * @return Whether the string is a valid palindrome     */  public static boolean isPalindrome(String s) {        if(s == null){        return true;// Write your code here        }        s  = s.toUpperCase();        int height = s.length()-1;        int low = 0;        while(low < height){        while(low < height && !isRight(s.charAt(low))){        low++;        }        while(low < height && !isRight(s.charAt(height))){        height--;        }        if(s.charAt(low) != s.charAt(height)){        return false;        }        else{        low ++;        height --;        }        }        return true;    }public static boolean isRight(char s){if(s>=65 && s<=90){return true;}if(s>=48 &&s<=57){return true;}return false;}}


0 0
原创粉丝点击