题目链接:https://leetcode.com/problems/excel-sheet-column-number/#/description
题目要求:实质上是26机制的数转化为十进制。
思路:举例来说,BAA=((B*26 + A) * 26 ) +A
Java代码如下:
public class Solution {
// 26进制的计算
public int titleToNumber(String s) {
if(s.length() == 0){
return 0;
}
int result = s.charAt(0) - 'A' + 1;
for(int i=1; i<s.length(); i++){
result = result * 26 + (s.charAt(i) - 'A' + 1) ;
}
return result;
}
}