20241104 finished.

This commit is contained in:
jackfiled 2024-11-04 13:43:31 +08:00
parent 2e9902e321
commit 99d9f6e1a7
2 changed files with 46 additions and 0 deletions

View File

@ -294,3 +294,5 @@ mod p3259_maximum_energy_boost_from_two_drinks;
mod p3226_number_of_bit_changes_to_make_two_integers_equal;
mod p638_shopping_offers;
mod p633_sum_of_square_numbers;

View File

@ -0,0 +1,44 @@
/**
* [633] Sum of Square Numbers
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn judge_square_sum(c: i32) -> bool {
use std::collections::HashSet;
let mut set = HashSet::new();
let mut i = 0i64;
let c = c as i64;
while i.pow(2) <= c {
let value = c - i.pow(2);
set.insert(i.pow(2));
if set.contains(&value) {
return true;
}
i += 1;
}
false
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_633() {
assert!(Solution::judge_square_sum(5));
assert!(Solution::judge_square_sum(4));
assert!(!Solution::judge_square_sum(3));
assert!(Solution::judge_square_sum(2));
}
}