20240802 Finished

This commit is contained in:
jackfiled 2024-08-02 11:37:58 +08:00
parent bc583588af
commit bc296e9e95
2 changed files with 43 additions and 1 deletions

View File

@ -192,3 +192,4 @@ mod p201_bitwise_and_of_numbers_range;
mod p66_plus_one;
mod p172_factorial_trailing_zeroes;
mod p69_sqrtx;
mod p50_powx_n;

41
src/problem/p50_powx_n.rs Normal file
View File

@ -0,0 +1,41 @@
/**
* [50] Pow(x, n)
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn my_pow(x: f64, n: i32) -> f64 {
if n < 0 {
1f64 / Self::quick_pow(x, -n)
} else {
Self::quick_pow(x, n)
}
}
fn quick_pow(x: f64, n: i32) -> f64 {
if n == 0 {
1f64
} else {
let y = Self::quick_pow(x, n / 2);
if n % 2 == 0 {
y * y
} else {
y * y * x
}
}
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_50() {
}
}