Hash Table
Intuition\n Describe your first thoughts on how to solve this problem. \n1) There exist maximum $21 \cdot 21$ combinations for each number from $nums$ array.\n\
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1) There exist maximum $21 \\cdot 21$ combinations for each number from $nums$ array.\n\n2) It needs to use Hash Table to count almost equal pairs\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nHash Table\n\n# Complexity\n- Time complexity: $O(7 \\cdot 21 \\cdot 21 \\cdot n)$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $O(n + 7 \\cdot 21 \\cdot 22)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nwhere $n$ is the length of the $nums$ array\n\n# Code\n```rust []\nuse std::collections::{HashMap, HashSet};\n\nimpl Solution {\n    pub fn count_pairs(nums: Vec<i32>) -> i32 {\n        let n = nums.len(); \n\n        let mut h = HashMap::<i32, [i32; 2]>::new();        \n\n        for n in nums {\n            if h.contains_key(&n) {\n                let mut t = h[&n].clone();\n\n                t[1] += t[0];\n                t[0] += 1;      \n\n                h.insert(n, t);\n            } else {\n                h.insert(n, [1, 0]);\n            }\n\n            let mut s = HashSet::from([n]);\n\n            Self::check(n, &mut s, &mut h);\n\n            let mut v = Vec::new();\n\n            for &m in &s {\n                if m != n {\n                    v.push(m);\n                }\n            }\n\n            for m in v {\n                Self::check(m, &mut s, &mut h);\n            }\n        }   \n\n        let mut r = 0;\n\n        for t in h {\n            r += t.1[1];\n        } \n\n        r\n    }\n\n    pub fn check(mut n: i32, s: &mut HashSet<i32>, h: &mut HashMap<i32, [i32; 2]>) {\n        let mut v = [0; 7];\n\n        for i in 0..7 {\n            v[6-i] = n % 10;\n            n /= 10;\n        }\n\n        for i in 0..6 {\n            for j in i+1..7 {\n                if v[i] != v[j] {\n                    let d = Self::digit(&v, i, j);\n\n                    if !s.contains(&d) {\n                        if h.contains_key(&d) {\n                            let mut t = h[&d];\n\n                            t[1] += t[0];\n\n                            h.insert(d, t);\n                        }\n                        \n                        s.insert(d);\n                    }\n                }\n            }\n        }  \n    }\n\n    pub fn digit(v: &[i32; 7], i: usize, j: usize) -> i32 {\n        let mut r = 0;\n\n        for k in 0..7 {\n            let d = if k == i {v[j]} else if k == j {v[i]} else {v[k]};\n\n            r += d * 10_i32.pow(6 - k as u32);\n        }\n\n        r\n    }\n}\n```
['Hash Table', 'Rust']