diff --git a/342_power_of_four/Cargo.lock b/342_power_of_four/Cargo.lock new file mode 100644 index 0000000..9994101 --- /dev/null +++ b/342_power_of_four/Cargo.lock @@ -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" diff --git a/342_power_of_four/Cargo.toml b/342_power_of_four/Cargo.toml new file mode 100644 index 0000000..ad3a66a --- /dev/null +++ b/342_power_of_four/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "power_of_four" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/342_power_of_four/src/main.rs b/342_power_of_four/src/main.rs new file mode 100644 index 0000000..85dcc94 --- /dev/null +++ b/342_power_of_four/src/main.rs @@ -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 + } +}