Title:Excel Sheet Column Number 171
Difficulty:Easy
原题leetcode地址: https://leetcode.com/problems/excel-sheet-column-number/submissions/
1. 10进制转换成26进制
时间复杂度:O(n),一次一层for循环。
空间复杂度:O(1),没有申请额外空间。
/**
* 10进制转换26进制问题
* @param s
* @return
*/
public static int titleToNumber(String s) {
int res = 0;
for (int i = 0; i < s.length(); i++) {
res += (s.charAt(i) - 'A' + 1) * Math.pow(26, s.length() - i - 1);
}
return res;
}