January 02, 2020

168. Excel Sheet Column Title

168. Excel Sheet Column Title

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

        return sb.toString();
    }
}
comments powered by Disqus