YuAn


  • 首頁

  • 目錄

  • 分類

  • 標籤

  • 關於我

  • 檢索

1732. Find the Highest Altitude

發表於 2023-12-21 | 分類於 leetcode

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int largestAltitude(vector<int>& gain) {
int mx_height = 0;
int cur_height = 0;
for(int g:gain){
cur_height += g;
mx_height = max(mx_height, cur_height);
}
return mx_height;
}
};

analysis

  • time complexity O(n)
  • space complexity O(1)
# Prefix Sum
2600. K Items With the Maximum Sum
1493. Longest Subarray of 1's After Deleting One Element
  • 文章目錄
  • 本站概覽

642 文章
20 分類
53 標籤
GitHub E-Mail FB Page Instagram
近期文章
  • 1750. Minimum Length of String After Deleting Similar Ends
  • 948. Bag of Tokens
  • 2864. Maximum Odd Binary Number
  • 2570. Merge Two 2D Arrays by Summing Values
  • 1074. Number of Submatrices That Sum to Target
  1. 1. problem
  2. 2. solution
  3. 3. analysis
© 2022 — 2024 YU-AN, Chen
由 Hexo 強力驅動
|
主題 — NexT.Mist v5.1.4