From b76354feb33b1bd0eaa43a3e6c60f79225476fd7 Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Mon, 18 Aug 2025 11:12:23 +0800 Subject: [PATCH] feat: add initial implementation of power of four solution with main function --- 342_power_of_four/Cargo.lock | 7 +++++++ 342_power_of_four/Cargo.toml | 6 ++++++ 342_power_of_four/src/main.rs | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 342_power_of_four/Cargo.lock create mode 100644 342_power_of_four/Cargo.toml create mode 100644 342_power_of_four/src/main.rs 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 + } +}