feat: 342_power_of_four
This commit is contained in:
parent
df5a8b2939
commit
b1d019a05d
7
342_power_of_four/Cargo.lock
generated
Normal file
7
342_power_of_four/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "power_of_four"
|
||||
version = "0.1.0"
|
6
342_power_of_four/Cargo.toml
Normal file
6
342_power_of_four/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "power_of_four"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
25
342_power_of_four/src/main.rs
Normal file
25
342_power_of_four/src/main.rs
Normal file
@ -0,0 +1,25 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
struct Solution;
|
||||
|
||||
impl Solution {
|
||||
pub fn is_power_of_four(mut n: i32) -> bool {
|
||||
if n <= 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
while n > 0 {
|
||||
if n == 1 {
|
||||
return true
|
||||
}
|
||||
if n % 4 != 0 {
|
||||
return false;
|
||||
}
|
||||
n /= 4;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user