C solution: Easy & Fast


  • 0
    I
    #define HEX_MAP(x) ((x)["0123456789abcdef"])
    
    char    *toHex(int num)
    {
        static char     tab[0x20];
        char            *p = tab + 0x20;
        unsigned int    value = num;
        
        *--p = HEX_MAP(value & 15); 
        while (0 != (value >>= 4))
            *--p = HEX_MAP(value & 15);
        return (p);
    }
    

Log in to reply
 

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