Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
*/
Loading