Rust - HashMap and BTreeSet
Solution - github\n\nProblem List\n#HashMap - github\n#TreeSet - github\n\n\nuse std::collections::{HashMap, BTreeSet};\n\n/// @author: Leon\n/// https://leetco
Solution - [github](https://github.com/An7One/lc_soln_rust_leon/tree/main/src/leetcode/ood/lvl2/lc2349)\n\n<b>Problem List</b>\n#HashMap - [github](https://github.com/An7One/leetcode-problems-by-tag-an7one/tree/main/txt/by_data_structure/map/hashmap)\n#TreeSet - [github](https://github.com/An7One/leetcode-problems-by-tag-an7one/blob/main/txt/by_data_structure/set/treeset.txt)\n\n```\nuse std::collections::{HashMap, BTreeSet};\n\n/// @author: Leon\n/// https://leetcode.com/problems/design-a-number-container-system/\n/// Time Complexities:\n///         `new()`:    O(1)\n///         `change()`: O(1)\n///         `find()`:   O(1)\n/// Space Complexity:   O(N)\nstruct NumberContainers {\n    num_to_indices: HashMap<i32, BTreeSet<i32>>,\n    idx_to_num: HashMap<i32, i32>,\n}\n\nimpl NumberContainers {\n\n    fn new() -> Self {\n        NumberContainers{\n            num_to_indices: HashMap::new(),\n            idx_to_num: HashMap::new(),\n        }\n    }\n    \n    fn change(&mut self, index: i32, number: i32) {\n        if let Some(&num) = self.idx_to_num.get(&index){\n            self.num_to_indices.entry(num).or_default().remove(&index);\n        }\n        self.num_to_indices.entry(number).or_default().insert(index);\n        self.idx_to_num.insert(index, number);\n    }\n    \n    fn find(&self, number: i32) -> i32 {\n        if let Some(indices) = self.num_to_indices.get(&number){\n            *indices.iter().next().unwrap_or(&-1)\n            // `first()` still is an unstable feature now\n\t\t\t// https://github.com/rust-lang/rust/issues/62924\n        }else{\n            -1\n        }\n    }\n}\n```
['Rust']