Solution in C


  • 0
    H
    int reverse(int x) {
        int y = (x > 0) ? x : (0 - x);
    	int z = 0;
    	while (y > 0)
    	{
    		z = z * 10 + (y % 10);
    		y = y / 10;
    		if ((y > 0) && (z > 0x7FFFFFFF / 10))
    		{
    			return 0;
    		}
    	}
    
    	if (z < 0)
    	{
    		return 0;
    	}
    	y = (x > 0) ? z : (0 - z);
    
    	return y;
    }
    

Log in to reply
 

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