My Java solution with one line


  • 0
    A
     public String convertToTitle(int n) {
            StringBuffer sb = new StringBuffer();
        	return n>26
        			?sb.append(convertToTitle((n-1)/26)).append((n%26==0?"Z":""+(char)((n%26)-1+(int)'A'))).toString()
        			:(n==26?"Z":""+(char)((n%26)-1+(int)'A'));
        }
    }

Log in to reply
 

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