Easy recursive solution in Java (this is still efficient, cause log by 26!)

  • 3
    public class Solution {
        public String convertToTitle(int n) {
            // 0-25 -> A-Z, so n will dercrease by 1
            n = n-1;
                return ""+(char)(n+65);
                return convertToTitle(n/26)+""+(char)(n%26+65);

Log in to reply

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