My sol is exceeding time but its same as editorial solution


#1

int Solution::power(string A) {

int cary=0;

string x="";

if(A.size()==1)
{
    if(A[0]=='2' || A[0]=='4' || A[0]=='8')return 1;
    else return 0;
}

int n;

while(A!="1")
{
    n=A.size();
    for(int i=0;i<n;i++)
    {
        x+=to_string(((A[i]-'0')+cary*10)/2);
        if(i==0 && (x[0]-'0'==0))x="";
        cary=((A[i]-'0')+cary*10)%2;
    
    }
    if(cary==1)return 0;
    A=x;
    x="";
}
return 1;

}