Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SuryaPratapK/e095b55ae5d7d97310c87cada3f8d586 to your computer and use it in GitHub Desktop.
Save SuryaPratapK/e095b55ae5d7d97310c87cada3f8d586 to your computer and use it in GitHub Desktop.
class Solution {
public:
bool checkPowersOfThree(int n) {
//All the digits of base-3 number must be either 0 or 1
while(n){
if(n%3==2)
return false;
n/=3;
}
return true;
}
};
/*
//JAVA
class Solution {
public boolean checkPowersOfThree(int n) {
// All the digits of base-3 number must be either 0 or 1
while (n > 0) {
if (n % 3 == 2) {
return false;
}
n /= 3;
}
return true;
}
}
#Python
class Solution:
def checkPowersOfThree(self, n: int) -> bool:
# All the digits of base-3 number must be either 0 or 1
while n > 0:
if n % 3 == 2:
return False
n //= 3
return True
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment