C++ Simple and Clean Code | Faster than 100%
Consider 0 is the special case.\n2. Store a flag indicating if the number is negative or not.\n3. Convert the absolute value of the number.\n4. Because string i
1. Consider `0` is the special case.\n2. Store a flag indicating if the number is negative or not.\n3. Convert the absolute value of the number.\n4. Because `string` is a last-in-first-out (LIFO) data structure, it is possible to add result in the correct order by either:\n\t1. Using `append` or `push_back` and reverse the string after the conversion loop.\n\t2. Using a `queue` instead of `string` which is still a good solution considering the space comlexity is `O(logn)`\n\n```\nstring convertToBase7(int num) {\n    if(num == 0)\n        return "0";\n    string base7Num;\n    bool isNegative = num < 0;\n    num = abs(num);\n    while (num) {\n        base7Num += to_string(num % 7);\n        num /= 7;\n    }\n    reverse(base7Num.begin(), base7Num.end());\n    return isNegative ? "-" + base7Num : base7Num;\n}\n```
['C']