Easy Java solution using BigInteger


#1

import java.math.*;
public class Solution {
public int power(String A) {
if(A.equals(“1”))
return 0;
BigInteger a=new BigInteger(A);
BigInteger a2=new BigInteger(“2”);
BigInteger a1=new BigInteger(“1”);
BigInteger a0=new BigInteger(“0”);
while(a.compareTo(a1)==1)
{
if(a.mod(a2).compareTo(a0)==0)
a=a.divide(a2);
else
return 0;
}
if(a.compareTo(a1)==0)
return 1;
else
return 0;
}
}