File tree Expand file tree Collapse file tree 3 files changed +19
-19
lines changed
g1001_1100/s1044_longest_duplicate_substring
g2501_2600/s2551_put_marbles_in_bags
g3301_3400/s3367_maximize_sum_of_weights_after_edge_removals Expand file tree Collapse file tree 3 files changed +19
-19
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ package g1001_1100.s1044_longest_duplicate_substring
6
6
class Solution {
7
7
private lateinit var hsh: LongArray
8
8
private lateinit var pw: LongArray
9
- private val cnt: Array <MutableList <Int >? > = arrayOfNulls (26 )
9
+ private val cnt: Array <MutableList <Int >> = Array (26 ) { ArrayList () }
10
10
11
11
fun longestDupSubstring (s : String ): String {
12
12
val n = s.length
@@ -20,17 +20,17 @@ class Solution {
20
20
for (j in 1 .. n) {
21
21
hsh[j] = (hsh[j - 1 ] * base + s[j - 1 ].code.toLong()) % MOD
22
22
pw[j] = pw[j - 1 ] * base % MOD
23
- cnt[s[j - 1 ].code - ' a' .code]!! .add(j - 1 )
23
+ cnt[s[j - 1 ].code - ' a' .code].add(j - 1 )
24
24
}
25
25
var ans = " "
26
26
for (i in 0 .. 25 ) {
27
- if (cnt[i]!! .isEmpty()) {
27
+ if (cnt[i].isEmpty()) {
28
28
continue
29
29
}
30
- val idx: MutableList <Int >? = cnt[i]
31
- var set: MutableSet <Long ? >
30
+ val idx: MutableList <Int > = cnt[i]
31
+ var set: MutableSet <Long >
32
32
var lo = 1
33
- var hi = n - idx!! [0 ]
33
+ var hi = n - idx[0 ]
34
34
while (lo <= hi) {
35
35
val len = (lo + hi) / 2
36
36
set = HashSet ()
Original file line number Diff line number Diff line change @@ -7,27 +7,27 @@ import java.util.PriorityQueue
7
7
8
8
class Solution {
9
9
fun putMarbles (weights : IntArray , k : Int ): Long {
10
- // Map<Pair<Integer, Integer>, long[]> memo = new HashMap<>();
11
- // long[] res = dfs(weights, 0, k, memo);
12
- // return res[1] - res[0];
13
- if (k == 1 || k == weights.size) return 0
10
+ if (k == 1 || k == weights.size) {
11
+ return 0
12
+ }
14
13
val min = PriorityQueue <Long >()
15
- val max = PriorityQueue { a: Long? , b: Long? ->
16
- java.lang.Long .compare(
17
- b!! ,
18
- a!! ,
19
- )
14
+ val max = PriorityQueue { a: Long , b: Long ->
15
+ b.compareTo(a)
20
16
}
21
17
for (i in 0 until weights.size - 1 ) {
22
18
val sum = weights[i].toLong() + weights[i + 1 ]
23
19
min.offer(sum)
24
20
max.offer(sum)
25
- if (min.size == k) min.poll()
26
- if (max.size == k) max.poll()
21
+ if (min.size == k) {
22
+ min.poll()
23
+ }
24
+ if (max.size == k) {
25
+ max.poll()
26
+ }
27
27
}
28
28
var res: Long = 0
29
29
while (max.isNotEmpty()) {
30
- res + = min.poll() - max.poll()!!
30
+ res + = min.poll() - max.poll()
31
31
}
32
32
return res
33
33
}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class Solution {
26
26
27
27
private fun dfs (v : Int , parent : Int ): LongArray {
28
28
var sum: Long = 0
29
- val pq = PriorityQueue <Long ? >()
29
+ val pq = PriorityQueue <Long >()
30
30
for (e in adj[v]) {
31
31
val w = if (e[0 ] == v) e[1 ] else e[0 ]
32
32
if (w == parent) {
You can’t perform that action at this time.
0 commit comments