Leetcode 1732. Find the Highest Altitude

Problem

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 integer array gain of length n where gain[i] is the net gain in altitude between points i​​​​​​ and i + 1 for all (0 <= i < n). Return the highest altitude of a point.

Algorithm

Accumulate data and judge.

Code

class Solution:
    def largestAltitude(self, gain: List[int]) -> int:
        ans, altitude = 0, 0
        glen = len(gain)
        for i in range(glen):
            altitude = altitude + gain[i]
            if ans < altitude:
                ans = altitude
        
        return ans

相关推荐

  1. LeetCode 1731, 151, 148

    2024-01-08 21:18:01       8 阅读
  2. LeetCode //C - 1732. Find the Highest Altitude

    2024-01-08 21:18:01       34 阅读
  3. Leetcode 1732. Find the Highest Altitude

    2024-01-08 21:18:01       40 阅读
  4. Leetcode14-判断句子是否为全字母句(1832

    2024-01-08 21:18:01       47 阅读
  5. leetcode - 1712. Ways to Split Array Into Three Subarrays

    2024-01-08 21:18:01       40 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-08 21:18:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-08 21:18:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-08 21:18:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-08 21:18:01       20 阅读

热门阅读

  1. SQL注入是什么呢?

    2024-01-08 21:18:01       40 阅读
  2. Vue面试题

    2024-01-08 21:18:01       48 阅读
  3. 「HDLBits题解」Vector3

    2024-01-08 21:18:01       41 阅读
  4. Hive实战处理(二十三)hive整合phoenix

    2024-01-08 21:18:01       31 阅读
  5. 深入理解 Golang 中的值类型和引用类型

    2024-01-08 21:18:01       41 阅读
  6. 什么是CHATGPT

    2024-01-08 21:18:01       35 阅读
  7. 【Istio】安装Istio1.20.1

    2024-01-08 21:18:01       38 阅读
  8. Trino:分区表上的SQL提交 & 查询流程浅析

    2024-01-08 21:18:01       35 阅读
  9. HarmonyOS@Extend装饰器:定义扩展组件样式

    2024-01-08 21:18:01       34 阅读
  10. DDD领域驱动设计(六)

    2024-01-08 21:18:01       39 阅读
  11. JDBC-常用API

    2024-01-08 21:18:01       41 阅读