题目描述
class Solution {
public String convertToTitle(int columnNumber) {
//26进制!参考十进制转十六进制0~25代表A~Z
StringBuilder sb=new StringBuilder();
while(columnNumber>0){
//余数转成字符
int temp=(columnNumber-1)%26;
char tempChar=(char)(temp+65);
//除以26
columnNumber=(columnNumber-1)/26;
//从下往上写,所以要反转
sb.append(tempChar);
}
return sb.reverse().toString();
}
}
运行截图