파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 8. 24. 23:45

https://leetcode.com/problems/power-of-three/submissions/

 

Power of Three - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

오늘도 easy 난이도 문제.
생각보다 따질 조건들이 몇개 있음.

class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if n == 1:
            return True
        if n < 3:
            return False
        while n > 1:
            if n % 3 != 0:
                return False
            n //= 3
        return True
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.08.26
Today's Challenge  (0) 2022.08.25
Today's Challenge  (0) 2022.08.23
Today's Challenge  (0) 2022.08.22
Today's Challenge  (0) 2022.08.21
Comments