Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package g1001_1100.s1044_longest_duplicate_substring
class Solution {
private lateinit var hsh: LongArray
private lateinit var pw: LongArray
private val cnt: Array<MutableList<Int>?> = arrayOfNulls(26)
private val cnt: Array<MutableList<Int>> = Array(26) { ArrayList() }

fun longestDupSubstring(s: String): String {
val n = s.length
Expand All @@ -20,17 +20,17 @@ class Solution {
for (j in 1..n) {
hsh[j] = (hsh[j - 1] * base + s[j - 1].code.toLong()) % MOD
pw[j] = pw[j - 1] * base % MOD
cnt[s[j - 1].code - 'a'.code]!!.add(j - 1)
cnt[s[j - 1].code - 'a'.code].add(j - 1)
}
var ans = ""
for (i in 0..25) {
if (cnt[i]!!.isEmpty()) {
if (cnt[i].isEmpty()) {
continue
}
val idx: MutableList<Int>? = cnt[i]
var set: MutableSet<Long?>
val idx: MutableList<Int> = cnt[i]
var set: MutableSet<Long>
var lo = 1
var hi = n - idx!![0]
var hi = n - idx[0]
while (lo <= hi) {
val len = (lo + hi) / 2
set = HashSet()
Expand Down
24 changes: 12 additions & 12 deletions src/main/kotlin/g2501_2600/s2551_put_marbles_in_bags/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import java.util.PriorityQueue

class Solution {
fun putMarbles(weights: IntArray, k: Int): Long {
// Map<Pair<Integer, Integer>, long[]> memo = new HashMap<>();
// long[] res = dfs(weights, 0, k, memo);
// return res[1] - res[0];
if (k == 1 || k == weights.size) return 0
if (k == 1 || k == weights.size) {
return 0
}
val min = PriorityQueue<Long>()
val max = PriorityQueue { a: Long?, b: Long? ->
java.lang.Long.compare(
b!!,
a!!,
)
val max = PriorityQueue { a: Long, b: Long ->
b.compareTo(a)
}
for (i in 0 until weights.size - 1) {
val sum = weights[i].toLong() + weights[i + 1]
min.offer(sum)
max.offer(sum)
if (min.size == k) min.poll()
if (max.size == k) max.poll()
if (min.size == k) {
min.poll()
}
if (max.size == k) {
max.poll()
}
}
var res: Long = 0
while (max.isNotEmpty()) {
res += min.poll() - max.poll()!!
res += min.poll() - max.poll()
}
return res
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Solution {

private fun dfs(v: Int, parent: Int): LongArray {
var sum: Long = 0
val pq = PriorityQueue<Long?>()
val pq = PriorityQueue<Long>()
for (e in adj[v]) {
val w = if (e[0] == v) e[1] else e[0]
if (w == parent) {
Expand Down