Easy C++ Solution with simple and understandle logic

amazon
Tags: #<Tag:0x00007f24225cd760>

#1

// using a simple observation, if A is the given number then from question statement
// A = 2^k
// log (A) = k log (2)
// k = log(A)/log(2) = log2(A)

int Solution::power(string A) {
long double a = stold(A),b=0;

if (a==1) return 0;

b = log2(a);
if(floor(b) == b) return 1;

return 0;

}


#2

Bro, it won’t work because you can’t hold the string into an int container