Skip to content

Latest commit

 

History

History
17 lines (16 loc) · 475 Bytes

168.md

File metadata and controls

17 lines (16 loc) · 475 Bytes

#168. Excel Sheet Column Title 题目链接

由于A对应1,Z对应26,所以每次n先减一,然后插入到字符串最前面

public class Solution {
    public String convertToTitle(int n) {
        StringBuilder sb = new StringBuilder();
        while (n > 0) {
            n--;
            sb.insert(0, (char)(n % 26 + 'A'));
            n /= 26;
        }
        return sb.toString();
    }
}