Problem:
Given an integer, write a function to determine if it is a power of three.
Example 1:
Input: 27
Output: true
Example 2:
Input: 0
Output: false
Example 3:
Input: 9
Output: true
Example 4:
Input: 45
Output: false
Follow up:
Could you do it without using any loop / recursion?
-Summary-
1. Check if n is bigger than 0 for when input is 0
2. Check if given n can divide the maximum number for the power of three. (1162261467 = 3^19)
discussion을 보니 array 를 써서 intuitive하게 바로 푼 답도 있었다.
Two simple solutions without recursion or iteration: O(1) time and O(1) space - LeetCode Discuss
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
모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]
'LeetCode > Top Interview Q. - Easy' 카테고리의 다른 글
LeetCode.Number of 1 Bits [Bit] (0) | 2020.06.17 |
---|---|
LeetCode.Roman to Integer [Math] (0) | 2020.06.16 |
LeetCode. Count Primes [Math] (0) | 2020.06.14 |
LeetCode. Fizz Buzz [Math] (0) | 2020.06.13 |
LeetCode 5. Valid Parentheses [Strings, Stack] (0) | 2020.06.12 |
댓글