![JAR search and dependency download from the Maven repository](/logo.png)
g1801_1900.s1854_maximum_population_year.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g1801_1900.s1854_maximum_population_year
// #Easy #Array #Counting #2023_06_22_Time_148_ms_(90.00%)_Space_34.5_MB_(90.00%)
class Solution {
fun maximumPopulation(logs: Array): Int {
val arr = IntArray(101)
for (log in logs) {
arr[log[0] - 1950]++
arr[log[1] - 1950]--
}
for (i in 1..100) {
arr[i] += arr[i - 1]
}
var maxyear = 1950
var max = 0
for (i in 0..100) {
if (arr[i] > max) {
max = arr[i]
maxyear = i + 1950
}
}
return maxyear
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy