summaryrefslogtreecommitdiff
path: root/number-of-equivalent-domino-pairs/src/main.rs
blob: ff169071d9521d3aac34d4793619d65fef7f0499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    println!("Hello, world!");
}

struct Solution;

impl Solution {
    pub fn num_equiv_domino_pairs(dominoes: Vec<Vec<i32>>) -> i32 {
        let mut map = [0;100];
        for d in dominoes {
            if let [i,j] = d[..] {
                map[(i.max(j) * 10 + i.min(j)) as usize] += 1;
            }
        }
        map.iter().filter(|&&x| x > 1).map(|&x| (x *(x-1))/2).sum::<i32>()
    }
}