Skip to content

Commit

Permalink
solution/java/0901-online-stock-span.java
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-aniketsingh committed Feb 21, 2023
1 parent 4946fe4 commit 97d0ddb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions java/0901-online-stock-span.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class StockSpanner {
Stack<int[]> s = new Stack<>();

public StockSpanner() {

}

public int next(int price) {
int span=1;
while(!s.isEmpty() && s.peek()[0]<=price)
span+=s.pop()[1];
s.push(new int[]{price,span});
return span;
}
}

0 comments on commit 97d0ddb

Please sign in to comment.