본문 바로가기
JAVA

[리트코드/자바] 1732.find the highest altitude

by 동백05 2023. 7. 20.

https://leetcode.com/problems/find-the-highest-altitude/

 

Find the Highest Altitude - LeetCode

Can you solve this real interview question? Find the Highest Altitude - There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0. You are given an integ

leetcode.com

 

class Solution {
    public int largestAltitude(int[] gain) {
        int n=gain.length;
        int[] alti=new int[n+1];
        alti[0]=0;
        int max=0;
        for(int i=1;i<n+1;i++){
            alti[i]=alti[i-1]+gain[i-1];
            if(alti[i]>max){
                max=alti[i];
            }
}
        return max;
    }
}

댓글