Posted on

Description

Submission

class Solution {
public:
    string convertToBase7(int num) {
        if(num == 0) return "0";
        string sign = "";
        if(num < 0) {
            sign = "-";
            num = -num;
        }
        stringstream ss;
        for(; num != 0; num /= 7) {
            ss << num % 7;
        }
        string ret = ss.str();
        reverse(ret.begin(), ret.end());
        return sign + ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *