LeetCode1732.找到最高海拔

有一个自行车手打算进行一场公路骑行,这条路线总共由 n + 1 个不同海拔的点组成。自行车手从海拔为 0 的点 0 开始骑行。

给你一个长度为 n 的整数数组 gain ,其中 gain[i] 是点 i 和点 i + 1净海拔高度差0 <= i < n)。请你返回 最高点的海拔

示例 1:

复制代码
输入:gain = [-5,1,5,0,-7]
输出:1
解释:海拔高度依次为 [0,-5,-4,1,1,-6] 。最高海拔为 1 。

示例 2:

复制代码
输入:gain = [-4,-3,-2,-1,4,3,2]
输出:0
解释:海拔高度依次为 [0,-4,-7,-9,-10,-6,-3,-1] 。最高海拔为 0 。

提示:

  • n == gain.length
  • 1 <= n <= 100
  • -100 <= gain[i] <= 100
python 复制代码
class Solution:
    def largestAltitude(self, gain: List[int]) -> int:
        altitude = [0]
        hight = 0
        for i in range(len(gain)):
            hight += gain[i]
            altitude.append(hight)
        return max(altitude)
python 复制代码
class Solution:
    def largestAltitude(self, gain: List[int]) -> int:
        altitude = 0
        hight = 0
        for i in range(len(gain)):
            hight += gain[i]
            if hight > altitude:
                altitude = hight
        return altitude
相关推荐
吴佳浩2 小时前
大模型量化部署终极指南:让700亿参数的AI跑进你的显卡
人工智能·python·gpu
diegoXie3 小时前
Python / R 向量顺序分割与跨步分割
开发语言·python·r语言
程序员小白条3 小时前
0经验如何找实习?
java·开发语言·数据结构·数据库·链表
七牛云行业应用4 小时前
解决OSError: No space left... 给DeepSeek Agent装上无限云硬盘
python·架构设计·七牛云·deepseek·agent开发
liulilittle4 小时前
C++ 浮点数封装。
linux·服务器·开发语言·前端·网络·数据库·c++
BoBoZz194 小时前
CutWithScalars根据标量利用vtkContourFilter得到等值线
python·vtk·图形渲染·图形处理
失散134 小时前
Python——1 概述
开发语言·python
夏乌_Wx4 小时前
练题100天——DAY23:存在重复元素Ⅰ Ⅱ+两数之和
数据结构·算法·leetcode
萧鼎4 小时前
Python 图像哈希库 imagehash——从原理到实践
开发语言·python·哈希算法
qq_251533594 小时前
使用 Python 提取 MAC 地址
网络·python·macos