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.
2 parents 9a2b735 + 663f050 commit 3f3a100Copy full SHA for 3f3a100
1381. Design a Stack With Increment
@@ -0,0 +1,37 @@
1
+class CustomStack {
2
+public:
3
+ int k;
4
+ vector<int> v;
5
+ CustomStack(int maxSize) {
6
+ k = maxSize;
7
+ }
8
+
9
+ void push(int x) {
10
+ if(v.size()<k){
11
+ v.push_back(x);
12
13
14
15
+ int pop() {
16
+ if(v.size()>0){
17
+ int x = v[v.size()-1];
18
+ v.pop_back();
19
+ return x;
20
21
+ else return -1;
22
23
24
+ void increment(int t, int val) {
25
+ for(int i=0; i<min((int)v.size(), t); i++){
26
+ v[i]+=val;
27
28
29
+};
30
31
+/**
32
+ * Your CustomStack object will be instantiated and called as such:
33
+ * CustomStack* obj = new CustomStack(maxSize);
34
+ * obj->push(x);
35
+ * int param_2 = obj->pop();
36
+ * obj->increment(k,val);
37
+ */
0 commit comments