JAVA 0ms
\n\n\nclass Solution {\n    public String convertToBase7(int num) {\n        char sign = \'+\';\n        if (num < 0) {\n            sign = \'-\';\n            
![image](https://assets.leetcode.com/users/images/2d5b368f-d88d-42bb-9c67-d11c915f1d1d_1635151001.8564022.png)\n\n```\nclass Solution {\n    public String convertToBase7(int num) {\n        char sign = \'+\';\n        if (num < 0) {\n            sign = \'-\';\n            num *= -1;\n        }\n        \n        if (num == 0) return "0";\n        \n        StringBuilder res = new StringBuilder();\n        \n        while (num != 0) {\n            res.append(num % 7);\n            num /= 7;\n        }\n        \n        if (sign == \'-\') res.append(\'-\');\n        \n        return res.reverse().toString();\n    }\n}\n```
['Java']