Skip to content

Instantly share code, notes, and snippets.

@lienista
Last active October 31, 2022 06:19
Show Gist options
  • Select an option

  • Save lienista/ebba4181020058ae4810861f53ad7243 to your computer and use it in GitHub Desktop.

Select an option

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.
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