🎉 One-stop destination for all your technical interview Preparation 🎉
Given a string columnTitle that represents the column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
char*26+carry
formula.class Solution {
public:
int titleToNumber(string columnTitle)
{
int ans = 0;
for (auto x : columnTitle) {
int temp = x - 'A' + 1; // 'A'-'A' will be 0 so add 1 in it.
ans = ans * 26 + temp;
}
return ans;
}
};