Help me!!! Where is the runtime error? I've test in my Visual Stdio? > .<


  • 0
    U

    int reverse(int x)
    {

    int *number=new int;
    int  index=0;
    int X=x;
    bool isNegative=false;
    if(x<0)//if the number is negative
    {
    	X=-x;
    	isNegative=true;
    }
    
    while(X>0)//calculate the numbers in the array
    {
    	int temp=X%10;
    	number[index++]=temp;
    	X=X/10;
    }
    
    int returnNumber=0;
    for(int i=index-1; i>=0; i--)
    {
    	returnNumber+=number[i]*pow(double(10),index-i-1);
    }
    
    if(returnNumber>pow(double(2),31)-1 || -returnNumber<-pow(double(2),32))//check if overflows
    {
    	return 0;
    }
    
    else
    {
    	if(isNegative){return -returnNumber;}
    	else
    	{
    		return returnNumber;
    
    	}
    }
    

    }


Log in to reply
 

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