Easy And clean C++ solution in O(N) time and O(1) space


#1

int Solution::titleToNumber(string A) {
int n = A.size();
int size = n;
int sum = 0;
for(int i = 0 ; i< n ; i++, size–)
{
sum += pow(26, size-1)*(int(A[i])-64);
}

return sum;

}


#2

Actually, the time complexity is O(NlogN). pow() takes log(N) time