Not a good solution but it works c 68ms


  • 0
    W

    bool isPalindrome(int x) {
    if(x < 0) return false;
    int bit=1,count,i;

    for(count = 1; x%(int)pow(10.0,count) != x; count++) {
    	bit++;
    }
    //printf("%d\n", bit);
    
    for(i = 1; i <= (int)bit/2; i++)
    {
    	//printf("%d %d\n",x/(int)pow(10.0,bit-i)%10,x%(int)pow(10.0,i)/(int)pow(10.0,i-1) );
    	if( x/(int)pow(10.0,bit-i)%10 != x%(int)pow(10.0,i)/(int)pow(10.0,i-1) )
    		return false;
    	//x = x-(int)pow(10.0,bit-i)*x/(int)pow(10.0,bit-i)-x%(int)pow(10.0,i);
    }
    return true;
    

    }


Log in to reply
 

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