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
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
class Solution {
public:
int titleToNumber(string s) {
int res = 0;
for(int i=0; i < s.length(); i++) {
res = 26*res + (s[i]-'A'+1);
}
return res;
}
}
本文介绍了一种算法,该算法能够将Excel表格中的列标题转换为其对应的列号数字。例如,A对应1,Z对应26,而AA则对应27等。此算法对于处理Excel表格数据尤其有用。
489

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



