Skip to content

Commit 10dbac5

Browse files
committed
hello there this is optimized code for stock span problem
1 parent 5246f63 commit 10dbac5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class StockSpanner {
2+
Stack<int[]> s = new Stack<>();
3+
4+
public StockSpanner() {
5+
6+
}
7+
8+
public int next(int price) {
9+
int span=1;
10+
while(!s.isEmpty() && s.peek()[0]<=price)
11+
span+=s.pop()[1];
12+
s.push(new int[]{price,span});
13+
return span;
14+
}
15+
}

0 commit comments

Comments
 (0)