题目来源【Leetcode】
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
这道题就是纯数学的题:
class Solution {
public:
int titleToNumber(string s) {
int sum = 0;
reverse(s.begin(),s.end());
for(int i = 0; i < s.length(); i++){
sum += (s[i]-'A'+1)*pow(26,i);
}
return sum;
}
};
本文介绍了一种将Excel表格中的列标题转换为对应数字的算法实现。通过具体实例展示了如何利用逆序遍历字符串并结合26进制转换原理来解决此问题。
262

被折叠的 条评论
为什么被折叠?



