Skip to content

Commit cb52b0c

Browse files
committed
Twitter : implement update query
1 parent 4b9ce65 commit cb52b0c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Solution/Day-242.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <array>
3+
#include <numeric>
4+
#include <cassert>
5+
using namespace std;
6+
class Solution {
7+
public:
8+
array<int , 25>hour;
9+
10+
Solution () {
11+
fill (hour.begin(), hour.end(), 0);
12+
}
13+
14+
void update (int Hour, int subscriberIncreased) {
15+
hour.at(Hour) += subscriberIncreased;
16+
}
17+
18+
int query (int startHour, int endHour) {
19+
return accumulate(hour.begin()+startHour , hour.begin()+endHour , 0ll);
20+
}
21+
};
22+
int main(void){
23+
Solution s;
24+
s.update(1 , 25);
25+
s.update(2 , 25);
26+
s.update(2 , 25);
27+
s.update(3 , 25);
28+
assert(s.query(1 , 3) != 100);
29+
return 0;
30+
}

0 commit comments

Comments
 (0)