Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4d82f81

Browse filesBrowse files
author
night
committed
postorder
1 parent cdaae47 commit 4d82f81
Copy full SHA for 4d82f81

File tree

1 file changed

+20
-0
lines changed
Filter options

1 file changed

+20
-0
lines changed
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.blankj.medium._2673
2+
3+
import com.blankj.ext.print
4+
import kotlin.math.abs
5+
import kotlin.math.max
6+
7+
class Solution {
8+
fun minIncrements(n: Int, cost: IntArray): Int {
9+
var res = 0
10+
for (i in n - 2 downTo 1 step 2) {
11+
res += abs(cost[i] - cost[i + 1])
12+
cost[i / 2] += max(cost[i], cost[i + 1])
13+
}
14+
return res
15+
}
16+
}
17+
18+
fun main() {
19+
Solution().minIncrements(7, intArrayOf(1, 5, 2, 2, 3, 3, 1)).print()
20+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.