Skip to content

Commit f937a62

Browse files
authored
Improved tasks 106, 373, 1751, 2286
1 parent cd88997 commit f937a62

File tree

5 files changed

+12
-13
lines changed
  • src
    • main/kotlin
      • g0101_0200/s0107_binary_tree_level_order_traversal_ii
      • g0301_0400/s0373_find_k_pairs_with_smallest_sums
      • g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii
      • g2201_2300/s2286_booking_concert_tickets_in_groups
    • test/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii

5 files changed

+12
-13
lines changed

src/main/kotlin/g0101_0200/s0107_binary_tree_level_order_traversal_ii/Solution.kt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package g0101_0200.s0107_binary_tree_level_order_traversal_ii
55

66
import com_github_leetcode.TreeNode
77
import java.util.Collections
8-
import kotlin.collections.ArrayList
98

109
/*
1110
* Example:

src/main/kotlin/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.kt

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package g0301_0400.s0373_find_k_pairs_with_smallest_sums
33
// #Medium #Array #Heap_Priority_Queue #2022_11_22_Time_1809_ms_(80.95%)_Space_119.1_MB_(66.67%)
44

55
import java.util.PriorityQueue
6-
import kotlin.collections.ArrayList
76

87
class Solution {
98
private class Node(index: Int, num1: Int, num2: Int) {

src/main/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/Solution.kt

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ package g1701_1800.s1751_maximum_number_of_events_that_can_be_attended_ii
33
// #Hard #Array #Dynamic_Programming #Binary_Search
44
// #2023_06_18_Time_608_ms_(100.00%)_Space_104.6_MB_(100.00%)
55

6-
import java.util.Arrays
7-
86
@Suppress("NAME_SHADOWING")
97
class Solution {
108
fun maxValue(events: Array<IntArray>, k: Int): Int {
119
if (k == 1) {
12-
val value = Arrays.stream(events).max({ a: IntArray, b: IntArray -> a[2].compareTo(b[2]) })
13-
return if (value.isPresent) {
14-
value.get()[2]
15-
} else {
16-
throw NullPointerException()
17-
}
10+
val value = events.maxByOrNull { it[2] }
11+
return value?.get(2) ?: throw NullPointerException()
1812
}
1913
val n = events.size
2014
events.sortWith { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) }

src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/BookMyShow.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package g2201_2300.s2286_booking_concert_tickets_in_groups
44
// #2023_06_28_Time_1292_ms_(100.00%)_Space_98.3_MB_(100.00%)
55

66
import java.util.ArrayDeque
7-
import java.util.Arrays
87
import java.util.Deque
98

109
@Suppress("NAME_SHADOWING")
@@ -35,8 +34,8 @@ class BookMyShow(n: Int, private val m: Int) {
3534
numZerosLeft = IntArray(this.n + 2)
3635
// initialize max and total, for max we firstly set values to m
3736
// segments of size 1 are placed starting from this.n - 1
38-
Arrays.fill(max, this.n - 1, this.n + n - 1, m)
39-
Arrays.fill(total, this.n - 1, this.n + n - 1, m.toLong())
37+
max.fill(m, this.n - 1, this.n + n - 1)
38+
total.fill(m.toLong(), this.n - 1, this.n + n - 1)
4039
// calculate values of max and total for segments based on values of their children
4140
var i = this.n - 2
4241
var i1 = i * 2 + 1

src/test/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/SolutionTest.kt

+8
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ internal class SolutionTest {
3535
equalTo(9)
3636
)
3737
}
38+
39+
@Test
40+
fun maxValue4() {
41+
assertThat(
42+
Solution().maxValue(arrayOf(intArrayOf(1, 2, 4), intArrayOf(3, 4, 3), intArrayOf(2, 3, 10)), 1),
43+
equalTo(10)
44+
)
45+
}
3846
}

0 commit comments

Comments
 (0)