C++ Solution


  • 0
    M
    class Solution {
    public:
        string toHex(int num) {
            if (num == 0) return "0";
            char const c_hex_table[] = "0123456789abcdef";
            string result;
            uint32_t n = num;
            while (n) {
                result.insert(0, 1, c_hex_table[n & 0xF]);
                n >>= 4;
            }
            return result;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.