Power of 2 Time : Space : 12345678910111213141516int Solution::power(string A) { if(A == "1") return 0; while((A.back() - '0') % 2 == 0) { string B = ""; int carry = A[0] == '1' ? 1 : 0; for(int i = A[0] == '1' ? 1 : 0; i < A.length(); i++) { int now = carry * 10 + A[i] - '0'; char ch = now / 2 + '0'; B.push_back(ch); carry = now % 2; } swap(A,B); } return A == "1";}