Easy Solution with logic


#1

int Solution::titleToNumber(string A) {
//Find the length of string
int len=A.length();
long long int sum=0;
//A=1,B=2,C=3…
//AB=(26^1)value of A[i] + 26^0 value of A[i]
// For each character take the power of 26 with exponent=characters left
// Multiply with actual value of A[i]
//Sum all of them
for(int i=0;i<len;i++)
{
int temp=((int)A[i])-65+1;
int exp=len-i-1;
sum+=pow(26,exp)*temp;

}
return sum;

}