Question:


Method: A technique for investigating the paper list is described by gain, and then a maximum value is selected.

package com.eric.leetcode

class FindTheHighestAltitude {
    fun largestAltitude(gains: IntArray): Int {
        val altitudes = mutableListOf<Int>()
        altitudes.add(0)
        for (gain in gains) {
            altitudes.add(gain + altitudes.last())
        }
        return altitudes.max() ?: 0
    }
}
Copy the code

Feel free to communicate if you have any questions

Specific code implementation can refer to Github