EASY C++ 100% O(log N)
Complexity
Time complexity: O(logn)
Space complexity: O(1)
Code

# Complexity
- Time complexity: $$O(log n)$$ 
- Space complexity: $$O(1)$$ 

# Code
```cpp []
class Solution {
public:
    string convertToBase7(int num) {
        string ans;
        bool flag = false;
        if(num < 0) {
            flag = true;
            num *= -1;
        }
        while(num >= 7) {
            char ch = (num%7)+'0';
            ans = ch + ans;
            num /= 7;
        }
        char ch = num +'0';
        ans = ch + ans;
        if(flag)
            ans = "-" + ans;
        return ans;
    }
};
```
['Math', 'C++']