C solution 3ms


  • 0
    A

    int power (int a,int b){
    int i,pd=1;

    if (b==0)
        return 1;
    
    for (i=0;i<b;i++)
        pd=pd*a;
    
    return pd;
    

    }
    int titleToNumber(char* s) {

    int i=0,sum=0,cn=0;
    for (i=0;*(s+i)!='\0';i++)
        cn++;
        
    for (i=0;i<cn;i++)
        sum+=(*(s+i)-'A'+1)*power(26,(cn-i-1));
        
    
    return sum ;
    

    }


Log in to reply
 

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