All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2801_2900.s2848_points_that_intersect_with_cars.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g2801_2900.s2848_points_that_intersect_with_cars

// #Easy #Hash_Table #Math #Prefix_Sum #2023_12_18_Time_190_ms_(100.00%)_Space_41.3_MB_(25.00%)

class Solution {
    fun numberOfPoints(nums: List>): Int {
        var min = 101
        var max = 0
        val count = IntArray(102)
        for (list in nums) {
            val num1 = list[0]
            val num2 = list[1]
            if (num1 < min) {
                min = num1
            }
            if (num2 > max) {
                max = num2
            }
            count[num1]--
            count[num2 + 1]++
        }
        var result = 0
        var balance = 0
        while (min <= max) {
            balance += count[min]
            if (balance < 0) {
                result++
            }
            min++
        }
        return result
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy