My short java solution without using string buffer and string builder


  • 9
    F
    public class Solution {
    public static String convertToTitle(int n) {
      int fac=26;String s="";
        while(n>0){
            n--;
            s=(char)(n%26+'A')+s;
            n/=fac;
        }
        return s;
    }    
    

    }


  • 0
    D

    Beware: for concatening strings (with the operator '+'), the JVM use a StringBuilder.


  • 5
    C

    Why people are upvoting this? Using String just to avoid using StringBuffer like everybody else? Do you know why we use StringBuilder not String most of the time? Because every time you concatenate the string using "+", you are creating a String object in the String pool. Don't ever do that man...


Log in to reply
 

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