![JAR search and dependency download from the Maven repository](/logo.png)
g0501_0600.s0575_distribute_candies.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 g0501_0600.s0575_distribute_candies
// #Easy #Array #Hash_Table #2023_01_23_Time_538_ms_(76.92%)_Space_47.3_MB_(69.23%)
class Solution {
fun distributeCandies(candyType: IntArray): Int {
val s: MutableSet = HashSet()
for (i in candyType) {
if (!s.contains(i)) {
s.add(i)
}
}
val canEat = candyType.size / 2
return if (s.size >= canEat) {
canEat
} else {
s.size
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy