Related to question Excel Sheet Column Title
Given a 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
// Source : https://oj.leetcode.com/problems/excel-sheet-column-number/
// Author : Chao Zeng
// Date : 2014-12-29
class Solution {
public:
int titleToNumber(string s) {
int n = s.length();
int ans = 0;;
for (int i = 0; i < n; i++){
int temp =(s[i] - 'A' + 1)*pow(26,n - i -1);
ans += temp;
}
return ans;
}
};