Why I get running error? it pass in vs2012!


  • 0
    X

    #define isstr(a) ((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))
    bool isPalindrome(char* s) {
    if(NULL == s) return true;
    if('\0' == s) return true;
    char* pa = s;
    char* pb = s;
    int k = 0;

    while(*pb++ != NULL)
    {
        k++;
    }
    
    while(pa != pb)
    {
    
        while(!isstr(*pa))
    	{
    		pa++;
    	}
        while(!isstr(*pb))
    	{
    		pb--;
    	}
    	if(pa > pb) 
    		break;
        if(*pa != *pb) 
    		return false;
    	else
    	{
    		pa++;
    		pb--;
    		if(pa > pb) 
    			break;
    	}
    }
    
    return true;
    

    }


  • 0
    K

    After writing code you should have to preserve it by selecting all of your code and click on {}. So, that a viewer can understand it well.


  • 0
    K
    You are trying to increase the address like a counter(see *pb++). That's why it doesn't do the intended task.

Log in to reply
 

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