https://leetcode.com/problems/power-of-three/description/
Power of Three - LeetCode
Power of Three - Given an integer n, return true if it is a power of three. Otherwise, return false. An integer n is a power of three, if there exists an integer x such that n == 3x. Example 1: Input: n = 27 Output: true Explanation: 27 = 33 Example 2:
leetcode.com
1
2
3
4
5
6
7
8
9
|
import math
def Log3(x):
return (math.log10(x) / math.log10(3))
class Solution:
def isPowerOfThree(self, n: int) -> bool:
if n <= 0:
return False
return (math.ceil(Log3(n)) == math.floor(Log3(n)))
|
cs |
https://sunchol21.tistory.com/1468 와 같은 내용입니다
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2496. Maximum Value of a String in an Array (0) | 2023.01.19 |
---|---|
leetcode 2535. Difference Between Element Sum and Digit Sum of an Array (0) | 2023.01.17 |
leetcode 263. Ugly Number (0) | 2023.01.17 |
leetcode 231. Power of Two (0) | 2023.01.17 |
백준 27219 Робинзон Крузо (0) | 2023.01.16 |
댓글