Skip to content

Commit f70a79b

Browse files
authored
Improved tasks 2973, 2983
1 parent 53c1181 commit f70a79b

File tree

2 files changed

+9
-9
lines changed
  • src/main/kotlin/g2901_3000

2 files changed

+9
-9
lines changed

src/main/kotlin/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/Solution.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class Solution {
4747
for (ne in next) {
4848
if (ne != p) {
4949
val r = dp(g, cost, ne, i)
50-
while (!r.min!!.isEmpty()) {
50+
while (r.min!!.isNotEmpty()) {
5151
val a = r.min!!.poll()
5252
pq2.add(a)
5353
}
54-
while (!r.max!!.isEmpty()) {
54+
while (r.max!!.isNotEmpty()) {
5555
val a = r.max!!.poll()
5656
pq.add(a)
5757
}
@@ -60,11 +60,11 @@ class Solution {
6060
if (pq.size + pq2.size < 3) {
6161
result[i] = 1
6262
} else {
63-
val a = if (!pq.isEmpty()) pq.poll() else 0
64-
val b = if (!pq.isEmpty()) pq.poll() else 0
65-
val c = if (!pq.isEmpty()) pq.poll() else 0
66-
val aa = if (!pq2.isEmpty()) pq2.poll() else 0
67-
val bb = if (!pq2.isEmpty()) pq2.poll() else 0
63+
val a = if (pq.isNotEmpty()) pq.poll() else 0
64+
val b = if (pq.isNotEmpty()) pq.poll() else 0
65+
val c = if (pq.isNotEmpty()) pq.poll() else 0
66+
val aa = if (pq2.isNotEmpty()) pq2.poll() else 0
67+
val bb = if (pq2.isNotEmpty()) pq2.poll() else 0
6868
result[i] = max(0, (a.toLong() * b * c))
6969
result[i] = max(result[i], max(0, (a.toLong() * aa * bb)))
7070
.toLong()

src/main/kotlin/g2901_3000/s2983_palindrome_rearrangement_queries/Solution.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Solution {
6565
// in the left half to match the right end of the right interval, this
6666
// means we do not need the right end of the right interval to go too far
6767
while (mp.containsKey(s[rptr]) ||
68-
(rptr >= n / 2 && s[rptr] == s[opp(rptr)] && mp.size == 0)
68+
(rptr >= n / 2 && s[rptr] == s[opp(rptr)] && mp.isEmpty())
6969
) {
7070
mp.computeIfPresent(s[rptr]) { _: Char?, v: Int -> if (v == 1) null else v - 1 }
7171
rptr--
@@ -79,7 +79,7 @@ class Solution {
7979
for (i in opp(problemPoint) downTo n / 2) {
8080
mp.compute(s[i]) { _: Char?, v: Int? -> if (v == null) 1 else v + 1 }
8181
while (mp.containsKey(s[lptr]) ||
82-
(lptr < n / 2 && s[lptr] == s[opp(lptr)] && mp.size == 0)
82+
(lptr < n / 2 && s[lptr] == s[opp(lptr)] && mp.isEmpty())
8383
) {
8484
mp.computeIfPresent(s[lptr]) { _: Char?, v: Int -> if (v == 1) null else v - 1 }
8585
lptr++

0 commit comments

Comments
 (0)