Very simple 0ms JAVA recursive solution


  • 0
    D
    public class Solution {
        public String convertToTitle(int n) {
            StringBuilder sb = new StringBuilder();
            convert(n - 1, sb);
            return sb.toString();
        }
        
        public void convert(int n, StringBuilder sb) {
            if (n > 25) convert(n / 26 - 1, sb);
            sb.append((char) ('A' + (n % 26)));
        }
    }
    

Log in to reply
 

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