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.
就是相當(dāng)于26進(jìn)制的計算缝裁,思路很簡單慧起。
class Solution {
public int titleToNumber(String s) {
int result = 0;
char[] arrays = s.toCharArray();
for (int i = arrays.length - 1, flag = 0; i >= 0; i--)
result += (arrays[i] - 64) * Math.pow(26, flag++);
return result;
}
}