day15
作者:互联网
题目描述
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();
}
}
运行截图
标签:columnNumber,26,tempChar,int,char,day15,sb 来源: https://blog.csdn.net/weixin_54209187/article/details/122300537