diff --git a/src/main/kotlin/g0101_0200/s0107_binary_tree_level_order_traversal_ii/Solution.kt b/src/main/kotlin/g0101_0200/s0107_binary_tree_level_order_traversal_ii/Solution.kt index 20f42b86f..240a1201b 100644 --- a/src/main/kotlin/g0101_0200/s0107_binary_tree_level_order_traversal_ii/Solution.kt +++ b/src/main/kotlin/g0101_0200/s0107_binary_tree_level_order_traversal_ii/Solution.kt @@ -5,7 +5,6 @@ package g0101_0200.s0107_binary_tree_level_order_traversal_ii import com_github_leetcode.TreeNode import java.util.Collections -import kotlin.collections.ArrayList /* * Example: diff --git a/src/main/kotlin/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.kt b/src/main/kotlin/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.kt index 85bee3cf5..8f5257945 100644 --- a/src/main/kotlin/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.kt +++ b/src/main/kotlin/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.kt @@ -3,7 +3,6 @@ package g0301_0400.s0373_find_k_pairs_with_smallest_sums // #Medium #Array #Heap_Priority_Queue #2022_11_22_Time_1809_ms_(80.95%)_Space_119.1_MB_(66.67%) import java.util.PriorityQueue -import kotlin.collections.ArrayList class Solution { private class Node(index: Int, num1: Int, num2: Int) { diff --git a/src/main/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/Solution.kt b/src/main/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/Solution.kt index f03ec90ba..c9add98ce 100644 --- a/src/main/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/Solution.kt +++ b/src/main/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/Solution.kt @@ -3,18 +3,12 @@ package g1701_1800.s1751_maximum_number_of_events_that_can_be_attended_ii // #Hard #Array #Dynamic_Programming #Binary_Search // #2023_06_18_Time_608_ms_(100.00%)_Space_104.6_MB_(100.00%) -import java.util.Arrays - @Suppress("NAME_SHADOWING") class Solution { fun maxValue(events: Array, k: Int): Int { if (k == 1) { - val value = Arrays.stream(events).max({ a: IntArray, b: IntArray -> a[2].compareTo(b[2]) }) - return if (value.isPresent) { - value.get()[2] - } else { - throw NullPointerException() - } + val value = events.maxByOrNull { it[2] } + return value?.get(2) ?: throw NullPointerException() } val n = events.size events.sortWith { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) } diff --git a/src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/BookMyShow.kt b/src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/BookMyShow.kt index 689e6a026..c9614f79f 100644 --- a/src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/BookMyShow.kt +++ b/src/main/kotlin/g2201_2300/s2286_booking_concert_tickets_in_groups/BookMyShow.kt @@ -4,7 +4,6 @@ package g2201_2300.s2286_booking_concert_tickets_in_groups // #2023_06_28_Time_1292_ms_(100.00%)_Space_98.3_MB_(100.00%) import java.util.ArrayDeque -import java.util.Arrays import java.util.Deque @Suppress("NAME_SHADOWING") @@ -35,8 +34,8 @@ class BookMyShow(n: Int, private val m: Int) { numZerosLeft = IntArray(this.n + 2) // initialize max and total, for max we firstly set values to m // segments of size 1 are placed starting from this.n - 1 - Arrays.fill(max, this.n - 1, this.n + n - 1, m) - Arrays.fill(total, this.n - 1, this.n + n - 1, m.toLong()) + max.fill(m, this.n - 1, this.n + n - 1) + total.fill(m.toLong(), this.n - 1, this.n + n - 1) // calculate values of max and total for segments based on values of their children var i = this.n - 2 var i1 = i * 2 + 1 diff --git a/src/test/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/SolutionTest.kt b/src/test/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/SolutionTest.kt index 669d13324..2f110501a 100644 --- a/src/test/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/SolutionTest.kt +++ b/src/test/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/SolutionTest.kt @@ -35,4 +35,12 @@ internal class SolutionTest { equalTo(9) ) } + + @Test + fun maxValue4() { + assertThat( + Solution().maxValue(arrayOf(intArrayOf(1, 2, 4), intArrayOf(3, 4, 3), intArrayOf(2, 3, 10)), 1), + equalTo(10) + ) + } }