Problem
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
Example
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
Solution
public class Solution {
/**
* @param s: a string
* @return: return a integer
*/
public int titleToNumber(String s) {
// write your code here
int res = 0;
for (int i = 0; i < s.length(); i++) {
if (i > 0) res *= 26;
char ch = s.charAt(i);
res += (ch-'A'+1);
}
return res;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。