Java : 5 lines


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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.