Skip to content

Commit d5b563e

Browse files
committed
Runtime: 8 ms (Top 70.94%) | Memory: 50.6 MB (Top 37.77%)
1 parent 6cb46f5 commit d5b563e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1+
// Runtime: 8 ms (Top 70.94%) | Memory: 50.6 MB (Top 37.77%)
12

23
class CustomStack {
3-
4+
45
int[] stack;
56
int top;
6-
7+
78
public CustomStack(int maxSize) {
8-
9+
910
//intialise the stack and the top
1011
stack= new int[maxSize];
1112
top=-1;
1213
}
13-
14+
1415
public void push(int x) {
15-
16+
1617
// if the stack is full just skip
1718
if( top==stack.length-1) return;
18-
19+
1920
//add to the stack
2021
top++;
2122
stack[top]=x;
2223
}
23-
24+
2425
public int pop() {
25-
26+
2627
//if stack is empty return -1
2728
if( top==-1) return -1;
28-
29-
29+
3030
//remove/pop the top element
3131
top--;
32-
return stack[top+1];
33-
32+
return stack[top+1];
33+
3434
}
35-
35+
3636
public void increment(int k, int val) {
37-
37+
3838
//got to increment the min of the elements present in the stack and k
3939
int n= Math.min(top+1,k);
40-
40+
4141
for( int i=0; i<n ; i++){
4242
stack[i]+=val;
4343
}
44-
44+
4545
}
46-
}
46+
}

0 commit comments

Comments
 (0)