diff --git a/src/main/java/review/leetcode901.java b/src/main/java/review/leetcode901.java new file mode 100644 index 0000000..0162e38 --- /dev/null +++ b/src/main/java/review/leetcode901.java @@ -0,0 +1,31 @@ +package review; + +import java.util.ArrayDeque; +import java.util.Deque; + +public class leetcode901 { + class StockSpanner { + + Deque stack; + int counter; + + public StockSpanner() { + stack = new ArrayDeque<>(); + counter = -1; + } + + public int next(int price) { + counter++; + while (!stack.isEmpty() && stack.peek()[1] <= price) { + int[] top = stack.pop(); + } + int tmp = -1; + if (!stack.isEmpty()) { + tmp = stack.peek()[0]; + } + + stack.push(new int[]{counter, price}); + return counter - tmp; + } + } +}