feat: add initial implementation of power of four solution with main function

This commit is contained in:
SquidSpirit 2025-08-18 11:12:23 +08:00
parent 3030d16bad
commit b76354feb3
3 changed files with 38 additions and 0 deletions

7
342_power_of_four/Cargo.lock generated Normal file
View 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"

View File

@ -0,0 +1,6 @@
[package]
name = "power_of_four"
version = "0.1.0"
edition = "2024"
[dependencies]

View 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
}
}