我的LeetCode代码仓:https://github.com/617076674/LeetCode
原题链接:https://leetcode-cn.com/problems/excel-sheet-column-number/description/
题目描述:
知识点:进制转换
思路:26进制数转10进制数
本题是LeetCode168——Excel表列名称的逆过程。
该26进制数个位数对应的范围是1 ~ 26,而不是0 ~ 25。
时间复杂度是O(n),其中n为列名称的长度。空间复杂度是O(1)。
JAVA代码:
public class Solution {
public int titleToNumber(String s) {
int result = 0;
for (int i = 0; i < s.length(); i++) {
result = result * 26 + s.charAt(i) - 'A' + 1;
}
return result;
}
}
LeetCode解题报告: