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 ans = 0;
for(int i = 0;i < s.size();i ++)
ans = 26 * ans + s[i] - 'A' + 1;
return ans;
}
};
本文介绍了一种将Excel工作表中的列标题转换为其对应数字编号的算法实现。例如,'A'转换为1,'Z'转换为26,而'AA'则转换为27等。该算法通过遍历字符串中的每个字符并计算其对应的数值来实现这一转换。
1407

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



