C solution: 2ms


  • 0
    I
    char    *convertToBase7(int num)
    {
        static char buf[0x11];
        char        *p = buf + 0x10;
        
        if (num >= 0)
        {
            *--p = '0' + (num % 7);
            while (0 != (num /= 7))
                *--p = '0' + (num % 7);
        }
        else
        {
            *--p = '0' - (num % 7);
            while (0 != (num /= 7))
                *--p = '0' - (num % 7);
            *--p = '-';
        }
        return (p);
    }
    

Log in to reply
 

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