Last updated 5 years ago
Was this helpful?
这道题类似于 get 一个数字的每一位
需要注意的是,insert 的时候是从个位向高位走的
public class Solution { public String convertToTitle(int n) { StringBuilder sb = new StringBuilder(); while (n > 0) { n--; sb.insert(0, (char)('A' + n % 26)); n /= 26; } return sb.toString(); } }