A solution on C


  • 0
    L

    int reverse(int x)
    {
    int an[20] = { 0 };
    int bn[20] = { 0 };
    int n, flag, ii = 0, geshu;
    int flag2;
    int m = 0;

    int jj=0, k;
    n = x;
    
    k = INT_MAX;
    do
    {
    	bn[jj] = k % 10;
    	flag2 = k / 10;
    	k = flag2;
    	jj++;
    } while (flag2 != 0);
    
    
    do
    {
    	an[ii] = n % 10;
    	flag = n / 10;
    	n = flag;
    	ii++;
    } while (flag != 0);
    
    
    geshu = ii;
    
    int kk=0;
    for (ii = jj - 1;ii >= 0;ii--,kk++)
    {
    	if (geshu < jj)
    		break;
    	if (abs(an[kk]) < bn[ii])
    		break;
    	else if (abs(an[kk]) == bn[ii])
    		continue;
    	else
    		return 0;
    
    }
    ii = 0;
    while (ii <geshu)
    {
    	m = an[ii] + m * 10;
    	ii++;
    	
    }
    return m;
    

    }


Log in to reply
 

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