We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c8a7c26 commit 9388637Copy full SHA for 9388637
scripts/algorithms/D/Design a Stack With Increment Operation/Design a Stack With Increment Operation.js
@@ -1,18 +1,17 @@
1
+// Runtime: 216 ms (Top 17.69%) | Memory: 50.1 MB (Top 69.23%)
2
var CustomStack = function(maxSize) {
3
this.stack = new Array(maxSize).fill(-1);
4
this.maxSize = maxSize;
5
this.size = 0;
6
};
7
-
8
CustomStack.prototype.push = function(x) {
9
if(this.size < this.maxSize){
10
this.stack[this.size] = x;
11
this.size++;
12
}
13
14
15
16
CustomStack.prototype.pop = function() {
17
if(this.size > 0){
18
this.size--;
@@ -21,12 +20,11 @@ CustomStack.prototype.pop = function() {
21
20
return -1;
22
23
24
25
CustomStack.prototype.increment = function(k, val) {
26
let count = k >= this.size ? this.size-1 : k-1;
27
+
28
while(count >= 0){
29
this.stack[count] += val;
30
count--;
31
32
-};
+};
0 commit comments