-
Notifications
You must be signed in to change notification settings - Fork 4
/
Solution.cpp
55 lines (48 loc) · 983 Bytes
/
Solution.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <tuple>
#include <deque>
#include <unordered_map>
#include <cmath>
using namespace std;
class CustomStack {
public:
vector<int> s;
int l;
CustomStack(int maxSize) {
l = maxSize;
s.clear();
s.reserve(l);
}
void push(int x) {
if (s.size()>=l) return;
s.push_back(x);
}
int pop() {
if (s.size()==0) return -1;
int res = s.back();
s.pop_back();
return res;
}
void increment(int k, int val) {
int i = 0;
while (k>0 and i<s.size()) {
s[i] += val;
k--;
i++;
}
}
};
/**
* Your CustomStack object will be instantiated and called as such:
* CustomStack* obj = new CustomStack(maxSize);
* obj->push(x);
* int param_2 = obj->pop();
* obj->increment(k,val);
*/
int main() {
return 0;
}