Java | Simple math | Beats 100% | Clean code
Approach\n Describe your approach to solving the problem. \nKeep track of the altitude at given point by starting from 0 and adding the gain value at each point
# Approach\n<!-- Describe your approach to solving the problem. -->\nKeep track of the altitude at given point by starting from `0` and adding the `gain` value at each point. Calculate the maximum altitude out of all the points.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public int largestAltitude(int[] gain) {\n    int altitude = 0, max = 0;\n\n    for (var g : gain) {\n      altitude += g;\n      max = Math.max(max, altitude);\n    }\n    return max;\n  }\n}\n```\nIf you like my solution, please upvote it!
['Array', 'Java']