My java solution


  • 1
    X

    public String convertToTitle(int n) {

        StringBuilder s = new StringBuilder();
        while (n > 0){
            s.insert(0, (n % 26 == 0)? 'Z' : (char)(64 + n % 26));
            n = (n % 26 == 0)?  n / 26 - 1 : n / 26;
        }
        return s.toString();
    }

Log in to reply
 

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