[Java/C++/Python] Iteration and Recursion
Iterative Solution\n\nPython\n\n    def convertToBase7(self, num):\n        n, res = abs(num), \'\'\n        while n:\n            res = str(n % 7) + res\n     
## Iterative Solution\n\n**Python**\n```\n    def convertToBase7(self, num):\n        n, res = abs(num), \'\'\n        while n:\n            res = str(n % 7) + res\n            n /= 7\n        return \'-\' * (num < 0) + res or "0"\n```\n\n\n\n## Recursive Solution\n\n**Java:**\n```\n    public String convertToBase7(int n) {\n        if (n < 0) return "-" + convertToBase7(-n);\n        if (n < 7) return Integer.toString(n);\n        return convertToBase7(n / 7) + Integer.toString(n % 7);\n    }\n```\n\n**C++:**\n```\n    string convertToBase7(int n) {\n        if (n < 0) return "-" + convertToBase7(-n);\n        if (n < 7) return to_string(n);\n        return convertToBase7(n / 7) + to_string(n % 7);\n    }\n```\n\n**Python:**\n```\n    def convertToBase7(self, n):\n        if n < 0: return \'-\' + self.convertToBase7(-n)\n        if n < 7: return str(n)\n        return self.convertToBase7(n // 7) + str(n % 7)\n```\n
[]