코딩테스트 풀이/JAVA
[LeetCode/Easy] 326. Power of Three
무지맘
2022. 11. 29. 13:22
1. Input
1) 정수 n
2. Output
1) n이 3의 거듭제곱이면 true를, 아니면 false를 반환
3. Constraint
1) - 2^31 <= n <= 2^31 - 1
4. Example
Input: n=27 -> Output: true
Input: n=28 -> Output: false
5. Code
1) 첫 코드(2022/07/19)
if(n==1) return true;
if(n<=0) return false;
double num = n;
while(num>=3)
num /= 3;
if(num==1) return true;
else return false;