-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlc2349.cpp
More file actions
42 lines (33 loc) · 903 Bytes
/
lc2349.cpp
File metadata and controls
42 lines (33 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <unordered_map>
#include <set>
using namespace std;
class NumberContainers {
private:
unordered_map<int,set<int>> numbers;
unordered_map<int,int> container;
public:
// LC2349 - Number Containers
NumberContainers() {
}
void change(int index, int number) {
if (container[index] != 0) {
int old_number = container[index];
numbers[old_number].erase(index);
}
container[index] = number;
numbers[number].insert(index);
}
int find(int number) {
if (numbers[number].empty())
return -1;
else {
return *numbers[number].begin();
}
}
};
/**
* Your NumberContainers object will be instantiated and called as such:
* NumberContainers* obj = new NumberContainers();
* obj->change(index,number);
* int param_2 = obj->find(number);
*/