LeetCode 825. Friends Of Appropriate Ages

Problem Statement


impl Solution {
pub fn num_friend_requests(ages: Vec<i32>) -> i32 {
let mut map = vec![0; 121];
for age in ages {
map[age as usize] += 1;
}
let mut ans = 0;
for a in 1..121 {
let ca = map[a];
for b in 1..121 {
let cb = map[b];
if b as f64 <= 0.5 * a as f64 + 7 as f64 || b > a || b > 100 && a < 100 {
continue;
}
ans += ca * cb;
if a == b {
ans -= ca;
}
}
}
return ans;
}
}