We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0a1b5bd commit 32ec0b5Copy full SHA for 32ec0b5
2349. Design a Number Container System
@@ -0,0 +1,32 @@
1
+class NumberContainers {
2
+public:
3
+ NumberContainers() {
4
+
5
+ }
6
+ map<int,set<int>>mp;
7
+ map<int,int>id;
8
+ void change(int index, int number) {
9
+ if(!id.count(index))
10
+ id[index]=number,
11
+ mp[id[index]].insert(index);
12
13
+ else
14
+ mp[id[index]].erase(index),
15
16
17
18
19
+ int find(int number) {
20
+ if(!mp[number].size())
21
+ return -1;
22
23
+ return *mp[number].begin();
24
25
+};
26
27
+/**
28
+ * Your NumberContainers object will be instantiated and called as such:
29
+ * NumberContainers* obj = new NumberContainers();
30
+ * obj->change(index,number);
31
+ * int param_2 = obj->find(number);
32
+ */
0 commit comments