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
66class Solution {
77 private lateinit var hsh: LongArray
88 private lateinit var pw: LongArray
9- private val cnt: Array <MutableList <Int >? > = arrayOfNulls (26 )
9+ private val cnt: Array <MutableList <Int >> = Array (26 ) { ArrayList () }
1010
1111 fun longestDupSubstring (s : String ): String {
1212 val n = s.length
@@ -20,17 +20,17 @@ class Solution {
2020 for (j in 1 .. n) {
2121 hsh[j] = (hsh[j - 1 ] * base + s[j - 1 ].code.toLong()) % MOD
2222 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 )
2424 }
2525 var ans = " "
2626 for (i in 0 .. 25 ) {
27- if (cnt[i]!! .isEmpty()) {
27+ if (cnt[i].isEmpty()) {
2828 continue
2929 }
30- val idx: MutableList <Int >? = cnt[i]
31- var set: MutableSet <Long ? >
30+ val idx: MutableList <Int > = cnt[i]
31+ var set: MutableSet <Long >
3232 var lo = 1
33- var hi = n - idx!! [0 ]
33+ var hi = n - idx[0 ]
3434 while (lo <= hi) {
3535 val len = (lo + hi) / 2
3636 set = HashSet ()
Original file line number Diff line number Diff line change @@ -7,27 +7,27 @@ import java.util.PriorityQueue
77
88class Solution {
99 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+ }
1413 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)
2016 }
2117 for (i in 0 until weights.size - 1 ) {
2218 val sum = weights[i].toLong() + weights[i + 1 ]
2319 min.offer(sum)
2420 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+ }
2727 }
2828 var res: Long = 0
2929 while (max.isNotEmpty()) {
30- res + = min.poll() - max.poll()!!
30+ res + = min.poll() - max.poll()
3131 }
3232 return res
3333 }
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class Solution {
2626
2727 private fun dfs (v : Int , parent : Int ): LongArray {
2828 var sum: Long = 0
29- val pq = PriorityQueue <Long ? >()
29+ val pq = PriorityQueue <Long >()
3030 for (e in adj[v]) {
3131 val w = if (e[0 ] == v) e[1 ] else e[0 ]
3232 if (w == parent) {
You can’t perform that action at this time.
0 commit comments