415 - 有效回文字符串

    xiaoxiao2021-04-18  61

    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; } }

    转载请注明原文地址: https://ju.6miu.com/read-675134.html

    最新回复(0)