simple solution with C++


  • 0
    D

    simple solution:

    class Solution {
    public:
        char hexMap[20] = "0123456789abcdef";
        string toHex(int num) {
            string res = "";
            int count = 0;
            if(num == 0)    return "0";
            while(num && count++ < 8)
            {
                res = hexMap[(num & 0xf)] + res;
                num >>= 4;
            }
            return res;
        }
    };
    

Log in to reply
 

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