We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 29cd4b1 commit e29a178Copy full SHA for e29a178
design-a-leaderboard.cpp
@@ -0,0 +1,29 @@
1
+class Leaderboard {
2
+public:
3
+
4
+ unordered_map<int, int> scores;
5
+ set<pair<int, int> > pairs;
6
7
+ Leaderboard() {
8
9
+ }
10
11
+ void addScore(int playerId, int score) {
12
+ pairs.erase({scores[playerId], playerId});
13
+ scores[playerId] += score;
14
+ pairs.insert({scores[playerId], playerId});
15
16
17
+ int top(int K) {
18
+ int res = 0;
19
+ int i = 0;
20
+ for (auto it = pairs.rbegin(); it != pairs.rend() && i < K; it++, i++) {
21
+ res += it->first;
22
23
+ return res;
24
25
+ void reset(int playerId) {
26
27
+ scores[playerId] = 0;
28
29
+};
0 commit comments