Title:Excel Sheet Column Title 168
Difficulty:Easy
原题leetcode地址: https://leetcode.com/problems/excel-sheet-column-title/
1. 10进制转换成26进制
时间复杂度:O(n),一次一层while循环。
空间复杂度:O(1),没有申请额外空间。
/**
* 10进制转换成26进制
* @param n
* @return
*/
public static String convertToTitle(int n) {
String res = "";
while (n > 0) {
res = (char)((n - 1) % 26 + 'A') + res;
n = (n - 1) / 26;
}
return res;
}