首页 > 解决方案 > Leetcode 125 为什么会失败

问题描述

我的代码如下:当输入是“一个人,一个计划,一条运河:巴拿马”时,我得到了错误,这是错误的。谁能告诉我为什么?谢谢!

class Solution {
    public boolean isPalindrome(String s) {
        String fixedS = "";
        
        for(char a: s.toCharArray()){
            if(Character.isLetter(a) || Character.isDigit(a)){
                fixedS += a;
            }
        fixedS = fixedS.toLowerCase();
            
        int start = 0;
        int end = fixedS.length()-1;
            
        while(start <= end){
            if(fixedS.charAt(start) != fixedS.charAt(end)){
                return false;
            }
            start++;
            end--;
        }
        }return true;
    }
}

标签: string

解决方案


推荐阅读