Easy C++ Solution | Different from Editorial


#1
string mult(string A){
    int carry = 0;
    int i = A.length() - 1;
    string res = "";
    while(i>=0){
        int prod = (A[i]-48)*2 + carry;
        res += (prod%10) + 48;
        carry = prod/10;
        i--;
    }
    while(carry > 0){
        res += (carry%10) + 48;
        carry/=10;
    }
    reverse(res.begin(), res.end());
    return res;
}
int Solution::power(string A) {
    string temp = "2";
    do{
        // cout<<temp<<"\n";
        if(temp.compare(A)==0) return 1;
        if(temp.length() > A.length()) return 0;
        temp = mult(temp);
    }
    while(true);
}