[JAVA] Consider n-1 ('A' -> 0, ...,'Z' -> 25) / T : O(N), S : O(N)


  • 0
    J
    class Solution {
        public String convertToTitle(int n) {
            StringBuffer strbuf = new StringBuffer();
            while(n > 0){
                strbuf.append((char)((n-1)%26 + 'A'));
                n = (n-1) / 26;
            }
            
            return strbuf.reverse().toString();
        }
    }
    

Log in to reply
 

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