LeetCode 171 Excel Sheet Column Number

时间:2023-03-10 16:01:08

Problem:

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

Summary:

将二十六进制数字转为十进制。

Analysis:

 class Solution {
public:
int titleToNumber(string s) {
int len = s.size();
int res = ; for (int i = ; i < len; i++) {
res += (s[len - i - ] - 'A' + ) * pow(, i);
} return res;
}
};