Posted on

Description

Submission

class Solution {
public:
    string toHex(int num) {
        if(num == 0) return "0";
        const string s = "0123456789abcdef";
        string ret;
        unsigned int n = num;
        for(; n > 0; n = (n >> 4)) {
            ret = s[n&15] + ret;
        }

        return ret;
    }
};

Leave a Reply

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