Leetcode/rust/2778_sum_of_squares_of_special_elements.rs
2024-03-08 21:05:31 +00:00

10 lines
224 B
Rust

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