public class Solution {
public String convertToTitle(int n) {
if (n < 1) {
return "";
}
StringBuilder sb = new StringBuilder();
while (n > 0) {
int mod = n % 26;
n = n / 26;
if (mod == 0) {
sb.append('Z');
n--;
} else {
char c = (char)('A' + mod - 1);
sb.append(c);
}
}
return sb.reverse().toString();
}
}
Excel Sheet Column Title
最新推荐文章于 2024-03-05 12:33:08 发布