It always tell me there's a compile error but I can't find it


  • 0

    string addBinary(string a, string b) {
    int r_t,i;
    int r_a=0,r_b=0,k=0;
    char *s;
    for (i=0;i<a.length();i++)
    {
    if(a[i]=='1')
    r_a+=pow(2,a.length()-i-1);
    }
    for (i=0;i<b.length();i++)
    {
    if(b[i]=='1')
    r_b+=pow(2,b.length()-i-1);
    }
    r_t = r_a+r_b;

    if (r_t==0)
    {
        string s("0");
        return s;
    }
    while(r_t!=0)
    {
        if((r_t%2)==1)
            s[k] = '1';
        else s[k] = '0';
        r_t/=2;
        k++;
    }
    s[k] = '\0';
    int n = strlen(s);
    char ss[n];
    for (i=0;i<n;i++)
        ss[i] = s[n-i-1];
    ss[n] = '\0';
    string result(ss);
    return result;
    

    };


  • 0
    L

    int rt,i;
    ...
    if (r_t==0)
    ...


Log in to reply
 

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