Excel Sheet Column Title

题目

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB

答案

class Solution {
    
    public String convertToTitle(int n) {
        if(n == 0) return "";
        char c = (char)((int)'A' + ((--n) % 26));
        return convertToTitle(n / 26) + c;
    }
}

你可能感兴趣的:(Excel Sheet Column Title)