Created
February 27, 2025 15:04
-
-
Save SuryaPratapK/e095b55ae5d7d97310c87cada3f8d586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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