Post

leetcode(리트코드)326-Power of Three

leetcode 326 - Power of Three 문제입니다.

1. 문제

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


2. Input , Output


3. 분류 및 난이도

Eazy 난이도 문제입니다.
Top 100 Interview 문제입니다.


4. 문제 해석

  • 들어온 n값이 3의 거듭제곱으로 나타낼 수 있으면 true 없으면 false를 리턴합니다.

5. code

c++

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
    bool isPowerOfThree(int n) {
        if(n<=0) return false;
        while(n!=1){
            if(n%3 !=0) return false;
            n/=3;
        }
        return true;
    }
};

6. 결과 및 후기, 개선점

코드에 대한 설명이 필요하신 분은 댓글을 달아주세요.!!

c++ 86% python ??%

This post is licensed under CC BY 4.0 by the author.