250x250
반응형
Notice
Recent Posts
Recent Comments
Link
N
(Leet Code c++)Power of Four 본문
728x90
반응형
342. Power of Four
Given an integer n, return true if it is a power of four. Otherwise, return false.
An integer n is a power of four, if there exists an integer x such that n == 4x.
Example 1:
Input: n = 16 Output: true
Example 2:
Input: n = 5 Output: false
Example 3:
Input: n = 1 Output: true
Constraints:
- -231 <= n <= 231 - 1
https://eunchanee.tistory.com/527
위 문제와 동일한 알고리즘.
class Solution {
public:
bool isPowerOfFour(int n) {
if(n <= 0){
return false;
}
while(n != 1){
if(n % 4){
return false;
}
n /= 4;
}
return true;
}
};
728x90
반응형
'Leet Code 알고리즘' 카테고리의 다른 글
(Leet Code c++)Intersection of Two Arrays (0) | 2021.08.03 |
---|---|
(Leet Code c++)Reverse Vowels of a String (0) | 2021.08.03 |
(Leet Code c++)Counting Bits (0) | 2021.08.03 |
(Leet Code c++)Power of Three (0) | 2021.08.03 |
(Leet Code c++)Range Sum Query (0) | 2021.08.02 |