原题链接:https://leetcode.com/problems/excel-sheet-column-number/
原题:
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
题意:
关于字母映射成数字。可以看成二十六进制转换成十进制。
这道题要求给你一个字符串,要求你返回它对应的列数。具体规则看 样例。
思路:
真心没什么好解释的,就是二十六进制转换成十进制。
AC代码:
class Solution {
public:
int titleToNumber(string s) {
int len=s.length()-1;
int result=0;
for(int i=0;i<=len;i++){
result+=(s[i]-‘A’+1)*pow(26,len-i);
}
return result;
}
};