-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path1381.java
More file actions
38 lines (32 loc) · 812 Bytes
/
1381.java
File metadata and controls
38 lines (32 loc) · 812 Bytes
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
class CustomStack {
private int[] arr;
private int index = 0;
public CustomStack(int maxSize) {
arr = new int[maxSize];
}
public void push(int x) {
if(index < this.arr.length){
this.arr[index] = x;
index++;
}
}
public int pop() {
if(index == 0){
return -1;
}
index--;
return this.arr[index];
}
public void increment(int k, int val) {
for(int i=0;i<Math.min(k, index);i++){
this.arr[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);
*/