Skip to content

Commit 578d437

Browse files
committed
Time: 112 ms (67.19%) | Memory: 195.9 MB (61.88%) - LeetSync
1 parent 4f59512 commit 578d437

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)