20241104 finished.
This commit is contained in:
parent
2e9902e321
commit
99d9f6e1a7
|
@ -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;
|
||||
|
|
44
src/problem/p633_sum_of_square_numbers.rs
Normal file
44
src/problem/p633_sum_of_square_numbers.rs
Normal 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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user