Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. class StockSpanner {
  2. Stack<int[]> stack;
  3. public StockSpanner() {
  4. stack = new Stack<>();
  5. }
  6.  
  7. public int next(int price) {
  8. int res = 1;
  9. while (!stack.isEmpty() && stack.peek()[0] <= price)
  10. res += stack.pop()[1];
  11. stack.push(new int[]{price, res});
  12. return res;
  13. }
  14. }
  15.  
  16. /**
  17. * Your StockSpanner object will be instantiated and called as such:
  18. * StockSpanner obj = new StockSpanner();
  19. * int param_1 = obj.next(price);
  20. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement