Working on basic cases till A=50 , please help me optimize


#1

string help(int A){
if(A==0)return “”;
else if(A%2==0)return “0”+help(A/2);
else return “1”+help(A/2);
}

int Solution::solve(int A) {

string s;
for(int i=1; i<pow(2,32);i++)
{
    s=help(i);
    string a=s;
    reverse( a.begin(), a.end());
    if(s.compare(a)==0)
    {
    A--;
    if(A==0) 
    break;
    }
}

int i =stoi(s);
int p=0;
int sum=0;
while(i!=0){
    int k=i%10;
    sum+= k*pow(2,p);
    i=i/10;
    p++;
}
return sum;

}