Skip to content

Commit d0c5583

Browse files
add 901
1 parent a9c2d15 commit d0c5583

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

contest/src/main/java/com/github/contest/design/DesignLeetcode.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,23 @@ class RecentCounter() {
351351
return queue.size
352352
}
353353

354+
}
355+
356+
/**
357+
* 901. Online Stock Span
358+
*/
359+
360+
class StockSpanner() {
361+
362+
private val stocks = ArrayDeque<Pair<Int, Int>>()
363+
364+
fun next(price: Int): Int {
365+
var span = 1
366+
367+
while (stocks.isNotEmpty() && stocks.last().first <= price) span += stocks.removeLast().second
368+
369+
stocks.addLast(price to span)
370+
return span
371+
}
372+
354373
}

0 commit comments

Comments
 (0)