mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
problems(rs): add „342. Power of Four“
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
10007a1821
commit
504fc1ba67
1 changed files with 15 additions and 0 deletions
15
problems/power-of-four.rs
Normal file
15
problems/power-of-four.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
impl Solution {
|
||||
pub fn is_power_of_four(n: i32) -> bool {
|
||||
if n == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut x = n;
|
||||
|
||||
while x % 4 == 0 {
|
||||
x >>= 2;
|
||||
}
|
||||
|
||||
x == 1
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue