problems(rs): add „342. Power of Four“

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-08-22 11:33:45 +02:00
parent 10007a1821
commit 504fc1ba67
Signed by: mfocko
GPG key ID: 7C47D46246790496

15
problems/power-of-four.rs Normal file
View 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
}
}