Easy C++ sol using string


#1

int Solution::power(string A)
{
string stop(A.size()-1,‘0’);
stop+=“2”;

if(A=="1"||A=="0")
return 0;

int n=A.size();
int k=0;

while(A>stop)
{
    int carry=0;
    int i=0;
    
    while(i<n)
    {
        int value=(10*carry+(A[i]-'0'));
        A[i]=value/2+'0';
        carry=value%2;
        ++i;
    }
    
    if((A[n-1]-'0')%2!=0)
    return 0;
}

return 1;

}