Solve 2778. Sum of Squares of Special Elements in Rust

This commit is contained in:
Kiril Kovachev 2024-03-08 21:04:44 +00:00
parent f54fe40496
commit 1d06cbd973

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