c++ | | O(N)
\n<!-- Describe your first thoughts on how to solve this problem. -\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:O(n)\n 
\n<!-- Describe your first thoughts on how to solve this problem. -\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string convertToBase7(int num) {\n        string s="";\n        int l=0;\n       if(num==0){\n           return "0";\n       }\n        if(num>0)\n        { int p=num;\n        while (p!=0){\n            l=p%7;\n            string h=to_string(l);\n            s=h+s;\n            p=p/7;\n        }\n        }else if (num<0){\n            int p=-num;\n         while (p!=0){\n            l=p%7;\n            string h=to_string(l);\n            s=h+s;\n            p=p/7;\n        }\n        s=\'-\'+s;\n        }\n        return s;\n\n    }\n};\n```
['C++']