I think there are bugs in my code.


  • 0
    B

    Is there any bug?

    '''int reverse(int x) {
    int count = 0, buf,result=0,number=0;

    for (buf = x; buf; count++)		//find how many character in number
    	buf /= 10;
    if (count > 9 && x % 10 > 2) return 0;  //overflow?
    for (buf = x; count > 0; count--) {
    	for (int i = count; i > 1; i--)
    		buf /= 10;
    	buf %= 10;
    	for(int i = 0; i < number; i++)
    		buf *= 10;
    	result += buf;
    	number++;
    		buf = x;
    }
    if(result > 0 && x > 0) //overflow?
        return result;
    else if(result < 0 && x < 0)
        return result;
    else
        return 0;
    

    }'''


Log in to reply
 

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