-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathpower-of-three.js
40 lines (38 loc) · 957 Bytes
/
power-of-three.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Given an integer, write a function to determine if it is a power of three.
//
//
// Follow up:
// Could you do it without using any loop / recursion?
//
//
// Credits:Special thanks to @dietpepsi for adding this problem and creating all test cases.
/**
* @param {number} n
* @return {boolean}
*/
var isPowerOfThree = function(n) {
switch(n) {
case 1:
case 3:
case 9:
case 27:
case 81:
case 243:
case 729:
case 2187:
case 6561:
case 19683:
case 59049:
case 177147:
case 531441:
case 1594323:
case 4782969:
case 14348907:
case 43046721:
case 129140163:
case 387420489:
case 1162261467:
return true;
default: return false;
}
};