We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4f59512 commit 578d437Copy full SHA for 578d437
2434-design-a-number-container-system/design-a-number-container-system.cpp
@@ -0,0 +1,16 @@
1
+class NumberContainers {
2
+public:
3
+ unordered_map<int, int> ind_num;
4
+ unordered_map<int, set<int>> num_inds;
5
+ void change(int index, int number) {
6
+ auto it = ind_num.find(index);
7
+ if (it != end(ind_num))
8
+ num_inds[it->second].erase(index);
9
+ ind_num[index] = number;
10
+ num_inds[number].insert(index);
11
+ }
12
+ int find(int number) {
13
+ auto it = num_inds.find(number);
14
+ return it == end(num_inds) || it->second.empty() ? -1 : *begin(it->second);
15
16
+};
0 commit comments