Rust Solution Using HashSet
Intuition\n Describe your first thoughts on how to solve this problem. \nUsing a hashset to iterate backward to calculate the negation part and to iterate forwa
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing a hashset to iterate backward to calculate the negation part and to iterate forward to calculate positive part separately.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n# Code\n```\nuse std::collections::HashSet;\n\nimpl Solution {\n    pub fn distinct_difference_array(nums: Vec<i32>) -> Vec<i32> {\n        let mut s = HashSet::new();\n        let n = nums.len();\n        let mut ret = vec![0; n]; \n\n        for i in (1 .. n).rev() {\n            s.insert(nums[i]);\n            ret[i - 1] -= s.len() as i32;\n        }\n\n        s.clear();\n        for i in 0 .. n {\n            s.insert(nums[i]);\n            ret[i] += s.len() as i32;\n        }\n\n        ret\n    }\n}\n```
['Rust']