342. Power of Four
Question
Given an integer
n
, returntrue
if it is a power of four. Otherwise, returnfalse
.An integer
n
is a power of four, if there exists an integerx
such thatn == 4<sup>x</sup>
.
Solution
递归,如果n小于等于零则返回false。
如果n等于1则返回true。
如果n可以除以4,则递归返回n/4。
Code
1 | class Solution { |
342. Power of Four