Skip to content

Commit

Permalink
Create 1381. Design a Stack With Increment
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Oct 2, 2024
1 parent 9a2b735 commit 663f050
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 1381. Design a Stack With Increment
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class CustomStack {
public:
int k;
vector<int> v;
CustomStack(int maxSize) {
k = maxSize;
}

void push(int x) {
if(v.size()<k){
v.push_back(x);
}
}

int pop() {
if(v.size()>0){
int x = v[v.size()-1];
v.pop_back();
return x;
}
else return -1;
}

void increment(int t, int val) {
for(int i=0; i<min((int)v.size(), t); i++){
v[i]+=val;
}
}
};

/**
* 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);
*/

0 comments on commit 663f050

Please sign in to comment.