Skip to content
This repository was archived by the owner on Apr 27, 2025. It is now read-only.

Commit 08e5a47

Browse files
committed
326. Power of Three
1 parent 4c19145 commit 08e5a47

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

326. Power of Three.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 326. Power of Three
2+
3+
### 2017-03-29
4+
5+
Given an integer, write a function to determine if it is a power of three.
6+
7+
**Follow up:**
8+
Could you do it without using any loop / recursion?
9+
10+
11+
12+
# Solution
13+
14+
```swift
15+
class Solution {
16+
func isPowerOfThree(_ n: Int) -> Bool {
17+
guard n > 0 else { return false }
18+
let num = log10(Double(n)) / log10(3)
19+
return (ceil(num) - num).isZero
20+
}
21+
}
22+
```
23+

0 commit comments

Comments
 (0)