본문 바로가기
python-algorithm

leetcode 326. Power of Three

by 무적김두칠 2023. 1. 17.

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 와 같은 내용입니다

반응형

댓글