File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ class NumberContainers {
2
+ public:
3
+ NumberContainers () {
4
+
5
+ }
6
+
7
+ void change (int index, int number) {
8
+ if (!m.count (index )) {
9
+ m[index ] = number;
10
+ mm[number].insert (index );
11
+ return ;
12
+ }
13
+
14
+ int num = m[index ];
15
+ mm[num].erase (index );
16
+ m[index ] = number;
17
+ mm[number].insert (index );
18
+ }
19
+
20
+ int find (int number) {
21
+ if (!mm.count (number) || mm[number].size () < 1 )
22
+ return -1 ;
23
+
24
+ return *(mm[number].begin ());
25
+ }
26
+
27
+ private:
28
+ unordered_map<int , int > m; // {idx, num}
29
+ unordered_map<int , set<int >> mm; // {num, idxs (sorted)}
30
+ };
31
+
32
+ /* *
33
+ * Your NumberContainers object will be instantiated and called as such:
34
+ * NumberContainers* obj = new NumberContainers();
35
+ * obj->change(index,number);
36
+ * int param_2 = obj->find(number);
37
+ */
You can’t perform that action at this time.
0 commit comments