Last active
October 31, 2022 06:19
-
-
Save lienista/ebba4181020058ae4810861f53ad7243 to your computer and use it in GitHub Desktop.
(Algorithms in Javascript) Leetcode 326. Power of Three - Given an integer, write a function to determine if it is a power of three.
This file contains hidden or 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
| const isPowerOfThree = (num) => { | |
| if(num === 1) { | |
| return true; | |
| } else if(num > 1 && num%3 === 0) { | |
| return isPowerOfThree(num/3); | |
| } else { | |
| return false; | |
| } | |
| } | |
| const x = 81; | |
| console.log(isPowerOfThree(x)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment