In this question, is ",." a valid Palindrome?


  • 0
    A

    The code below is accepted by OJ,but it will out put a false if the input is ",.". But according to the question,",." does not have any nuber or character so I think it is a valid Palindrome.
    Am I wrong?

    public boolean isPalindrome(String s) {
    			int cusorhead=0,cusortail=s.length()-1;
    	        while(cusorhead<cusortail){
    	            while(!Character.isLetterOrDigit(s.charAt(cusorhead))&&cusorhead<s.length()-1)cusorhead++;
                    while(!Character.isLetterOrDigit(s.charAt(cusortail))&&cusortail>0)cusortail--;
        		    if(Character.toLowerCase(s.charAt(cusorhead))!=Character.toLowerCase(s.charAt(cusortail)))
    	                return false;
        		    
        		    cusorhead++;cusortail--;
    	        }
    	              
    			return true;
    	        	        
    	    }

  • 0

    i think just only number(1,2..) and letter(a,A..ignore cases) are accepted


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.