엔지니어 게시판
LeetCode 솔루션 분류

[8/24] 326. Power of Three

컨텐츠 정보

본문

Easy
1314146Add to ListShare

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

Example 2:

Input: n = 0
Output: false

Example 3:

Input: n = 9
Output: true

 

Constraints:

  • -231 <= n <= 231 - 1

 

Follow up: Could you solve it without loops/recursion?
Accepted
509,082
Submissions
1,158,014
태그

관련자료

댓글 1

학부유학생님의 댓글

  • 익명
  • 작성일
Runtime: 134 ms, faster than 50.88% of Python3 online submissions for Power of Three.
Memory Usage: 13.9 MB, less than 57.97% of Python3 online submissions for Power of Three.
class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if n == 1: return True
        if n < 1: return False
        
        while n > 1 and n%3 == 0:
            n /= 3
            
        return True if n == 1 else False
전체 396 / 7 페이지
번호
제목
이름

최근글


인기글


새댓글


Stats


  • 현재 접속자 247 명
  • 오늘 방문자 2,102 명
  • 어제 방문자 6,705 명
  • 최대 방문자 11,134 명
  • 전체 회원수 1,108 명
알림 0