You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution {
boolisPowerOfThree(int n) {
if (n <1) returnfalse;
String nBase4 ="";
while (n !=0) nBase4 += (n %4).toString();
n ~/=3; // conversion to base 3int i =0;
while (i < nBase4.length -1)
if (nBase4[i++] !='0')
returnfalse; // checking if all digits in base 3 converted number except first one are 0return nBase4[i] =='1'; // check if starting digit is 1
}
}