Solve 2778. Sum of Squares of Special Elements in Rust
This commit is contained in:
parent
f54fe40496
commit
1d06cbd973
9
rust/2778_sum_of_squares_of_special_elements.rs
Normal file
9
rust/2778_sum_of_squares_of_special_elements.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
impl Solution {
|
||||||
|
pub fn sum_of_squares(nums: Vec<i32>) -> i32 {
|
||||||
|
let n = nums.len();
|
||||||
|
nums.iter().enumerate()
|
||||||
|
.filter(|(i, x)| n % (i+1) == 0)
|
||||||
|
.map(|(i, x)| x*x)
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user