Skip to content

Commit 46c66dc

Browse files
Merge pull request #206
add new problem 4.06
2 parents 87769c2 + d0c5583 commit 46c66dc

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

contest/src/main/java/com/github/contest/Execute.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import java.util.TreeMap
1717
fun main() {
1818

1919
findAnagrams("abnkjhgidhr", "abn").also { println(it) }
20+
2021
}
2122

2223
infix fun Int.myRange(to: Int): IntRange {

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.contest.design
22

3+
import java.util.LinkedList
4+
35
/**
46
* 1352. Product of the Last K Numbers
57
*/
@@ -331,4 +333,41 @@ class RLEIterator(private val encoding: IntArray) {
331333
return 0
332334
}
333335

336+
}
337+
338+
/**
339+
* 933. Number of Recent Calls
340+
*/
341+
342+
class RecentCounter() {
343+
344+
private val queue = LinkedList<Int>()
345+
346+
fun ping(t: Int): Int {
347+
queue.offer(t)
348+
349+
while (queue.peek() < t - 3000) queue.poll()
350+
351+
return queue.size
352+
}
353+
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+
334373
}

0 commit comments

Comments
 (0)