Best O(N) Solution
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n    int largestAltitude(vector<int>& gain) {\n        
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int largestAltitude(vector<int>& gain) {\n        int ans = 0, cur = 0;\n        for (int i = 0; i < gain.size(); i++) {\n            cur += gain[i];\n            ans = max (ans, cur);\n        }\n        return ans;\n    }\n};\n```
['C++']