Skip to content

Commit be7467c

Browse files
committed
chore: sync automated leetcode submissions with Runtime - 649 ms (50.00%), Memory - 84.4 MB (50.00%)
1 parent 1b82e9b commit be7467c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • 3351-maximize-happiness-of-selected-children
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
fun maximumHappinessSum(happiness: IntArray, k: Int): Long {
3+
happiness.sort()
4+
5+
var total: Long = 0
6+
val n = happiness.size
7+
8+
for (i in 0 until k) {
9+
val currentVal = happiness[n - 1 - i] - i
10+
11+
if (currentVal <= 0) break
12+
13+
total += currentVal.toLong()
14+
}
15+
16+
return total
17+
}
18+
}

0 commit comments

Comments
 (0)