Leetcode/rust/2778_sum_of_squares_of_special_elements.rs

9 lines
223 B
Rust
Raw Normal View History

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