3 line code in c++


#1

int Solution::power(string B) {
long double A=stold(B);
if(A==0|| A==1) return 0;
return floor(log2(A))==ceil(log2(A))?1:0;
}


#2

Can u plz explain this ?
I mean how does this work bcoz stol is giving out of bounds!!!


#3

use this to avoid that;
int i;
istringstream(str)>>i;
to convert string to integer


#4

long double has a max of 16 bits but surpringly this soln works. This should be giving an out of range exception for stold!!! HOW??


#5

if you wanted to be get rejected in your interview then use it.it helps to reject you in first round.