File tree 1 file changed +7
-6
lines changed
scripts/algorithms/D/Design a Stack With Increment Operation
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 35 ms (Top 95.05%) | Memory: 21.1 MB (Top 38.81%)
1
2
class CustomStack {
2
3
int *data;
3
4
int nextIndex;
@@ -8,15 +9,15 @@ class CustomStack {
8
9
nextIndex = 0 ;
9
10
capacity = maxSize;
10
11
}
11
-
12
+
12
13
void push (int x) {
13
14
if (nextIndex == capacity){
14
15
return ;
15
16
}
16
17
data[nextIndex] = x;
17
18
nextIndex++;
18
19
}
19
-
20
+
20
21
int pop () {
21
22
if (nextIndex == 0 ){
22
23
return -1 ;
@@ -25,12 +26,12 @@ class CustomStack {
25
26
nextIndex--;
26
27
return temp;
27
28
}
28
-
29
+
29
30
void increment (int k, int val) {
30
- // loop will run upto nextIndex if k >= nextIndex else runt upto k only
31
+ // loop will run upto nextIndex if k >= nextIndex else runt upto k only
31
32
int n = (k >= nextIndex) ? nextIndex : k;
32
33
for (int i = 0 ; i < n; i++){
33
- data[i] = data[i] + val;
34
+ data[i] = data[i] + val;
34
35
}
35
36
}
36
- };
37
+ };
You can’t perform that action at this time.
0 commit comments