LeetCode 982. Triples with Bitwise AND Equal To Zero

Problem Statement


use std::collections::HashMap;

impl Solution {
pub fn count_triplets(a: Vec<i32>) -> i32 {
let mut map = HashMap::new();
let mut ans = 0;
for i in 0..a.len() {
for j in 0..a.len() {
let val = map.entry(a[i] & a[j]).or_insert(0);
*val += 1;
}
}

for i in a {
for (key, val) in &map {
if key & i == 0 {
ans += *val;
}
}
}
return ans;
}
}