Easy c 0ms solution


  • 1
    char* toHex(int num) {
        if(num==0) return "0";
        unsigned int* unum = #
        char *res = (char*)malloc(9);
        res[8] = 0;
        int tmp;
        int i = 0;
        while(*unum){
            tmp = *unum & 0x0000000f;
            *(res+7-i) = tmp + ((tmp>9)?('a'-10):'0');
            *unum = *unum >> 4;
            i++;
        }
        return res+7-i+1;
    }
    

Log in to reply
 

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