![JAR search and dependency download from the Maven repository](/logo.png)
g2501_2600.s2591_distribute_money_to_maximum_children.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 g2501_2600.s2591_distribute_money_to_maximum_children
// #Easy #Math #Greedy #2023_07_12_Time_155_ms_(100.00%)_Space_34.2_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
fun distMoney(money: Int, children: Int): Int {
var money = money
if (children > money) return -1
money -= children
var ans: Int = money / 7
if (ans == children && money % 7 == 0) return ans
if (ans >= children) return children - 1
if (money % 7 == 3 && ans == children - 1) ans--
return ans
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy