[Prefix Sum, Easy] Find the Highest Altitude

송재호·2025년 3월 12일
0

https://leetcode.com/problems/find-the-highest-altitude/description/?envType=study-plan-v2&envId=leetcode-75

아주 쉬운 구간합 문제
따로 설명은 필요 없을 것 같다.

class Solution {
    public int largestAltitude(int[] gain) {
        
        int last = 0;
        int highest = last;

        for (int i=0; i<gain.length; i++) {
            last += gain[i];
            highest = Math.max(last, highest);
        }
        return highest;
    }
}
profile
식지 않는 감자

0개의 댓글