diff --git a/src/main/java/com/fishercoder/solutions/_1381.java b/src/main/java/com/fishercoder/solutions/_1381.java index 61024c2e8a..e4cb25c19f 100644 --- a/src/main/java/com/fishercoder/solutions/_1381.java +++ b/src/main/java/com/fishercoder/solutions/_1381.java @@ -79,4 +79,43 @@ public void increment(int k, int val) { } } } + + /** + * Implementation of Stack using Array + */ + public static class Solution2{ + public static class CustomStack { + private int top; + private int maxSize; + private int stack[]; + public CustomStack(int maxSize) { + this.maxSize = maxSize; + this.stack = new int[maxSize]; + } + + public void push(int x) { + if(top == maxSize) return; + stack[top] = x; + top++; + } + + public int pop() { + if(top == 0) + return -1; + int popValue = stack[top-1]; + stack[top-1] = 0; + top--; + return popValue; + } + + public void increment(int k, int val) { + if(top == 0 || k == 0) return; + for(int i = 0; i