Java 0ms Solution using StringBuilder
It is recommended using StringBuilder instead of String concatenation since, the latter is more expensive. Additionally, StringBuilder has .insert() method whic
It is recommended using StringBuilder instead of String concatenation since, the latter is more expensive. Additionally, StringBuilder has .insert() method which can be used to insert the character at 0th index. However, since StringBuilder uses array under the hood, it has to shift every character to the right in order to insert at the index. Thus I chose to append the characters and reverse it at once at return.\n```\nclass Solution {\n    public String convertToBase7(int num) {\n        StringBuilder s = new StringBuilder();\n        int n = Math.abs(num);\n        while(n / 7 != 0){\n            s.append(n % 7);\n            n /= 7;\n        }\n        s.append(n);\n        if(num < 0) s.append(\'-\');\n        return s.reverse().toString();\n    }\n}\n```
['String', 'Java']