C very simple solution,only 7 lines,3 ms


  • 0
    W
    char* convertToBase7(int num) {
        char *ret=calloc(10,sizeof(char));
        if(num==0) return "0";
        else if(num>0){
            char *tmp=convertToBase7(num/7);
            sprintf(ret,"%s%d",tmp=="0"?"":tmp,num%7,0);} 
        else sprintf(ret,"-%s",convertToBase7(abs(num)));
        return ret;
    }

Log in to reply
 

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