Python 3   ||   7 lines,  modular arithmetic   ||   T/S: 99% / 99%
\nclass Solution:\n    def convertToBase7(self, num: int) -> str:\n\n        if num == 0: return \'0\'\n\n        ans, n = \'\', abs(num)\n\n        while n:\n 
```\nclass Solution:\n    def convertToBase7(self, num: int) -> str:\n\n        if num == 0: return \'0\'\n\n        ans, n = \'\', abs(num)\n\n        while n:\n            n, m = divmod(n,7)\n            ans+=str(m)\n\n        if num < 0: ans+= \'-\'\n\n        return ans[::-1]\n```\n[https://leetcode.com/problems/base-7/submissions/587231651/](https://leetcode.com/problems/base-7/submissions/587231651/)\n\nI could be wrong, but I think that time complexity is *O*(log*N*) and space complexity is *O*(log*N*), in which *N* ~`int(num)`.
['Python3']