Leetcode 3147. Taking Maximum Energy From the Mystic Dungeon

1. 解题思路

这一题的话我们倒序看一下以各个位置作为终点时前面各个位置作为起点时的energy各是多少,取出其中的最大值即可。

2. 代码实现

给出python代码实现如下:

class Solution:
    def maximumEnergy(self, energy: List[int], k: int) -> int:
        n = len(energy)
        ans = -math.inf
        for i in range(k):
            s = 0
            for j in range(n-1-i, -1, -k):
                s += energy[j]
                ans = max(ans, s)
        return ans

提交代码评测得到:耗时1139ms,占用内存29.7MB。

相关推荐

  1. Leetcode 3187. Peaks in Array

    2024-05-13 01:22:03       28 阅读
  2. Leetcode 3147. Taking Maximum Energy From the Mystic Dungeon

    2024-05-13 01:22:03       31 阅读
  3. LeetCode347. Top K Frequent Elements

    2024-05-13 01:22:03       46 阅读
  4. 每日练习——leetcode77和347

    2024-05-13 01:22:03       40 阅读
  5. Leetcode 347:前K个高频元素

    2024-05-13 01:22:03       24 阅读
  6. Leetcode 3148. Maximum Difference Score in a Grid

    2024-05-13 01:22:03       34 阅读
  7. Leetcode 3145. Find Products of Elements of Big Array

    2024-05-13 01:22:03       35 阅读
  8. Leetcode 3149. Find the Minimum Cost Array Permutation

    2024-05-13 01:22:03       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-13 01:22:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-13 01:22:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-13 01:22:03       87 阅读
  4. Python语言-面向对象

    2024-05-13 01:22:03       96 阅读

热门阅读

  1. 前端工程化之---git hooks

    2024-05-13 01:22:03       28 阅读
  2. Git 剔除已经纳入版本管理的文件

    2024-05-13 01:22:03       31 阅读
  3. 代码随想录:二分查找相关题目推荐(35、34)

    2024-05-13 01:22:03       31 阅读
  4. 关于fmt的用法

    2024-05-13 01:22:03       28 阅读
  5. 【C++】string类的模拟实现

    2024-05-13 01:22:03       30 阅读
  6. HashMap在Jdk1.8之前并发扩容下的死循环

    2024-05-13 01:22:03       38 阅读
  7. QT作业4

    QT作业4

    2024-05-13 01:22:03      34 阅读
  8. 邦芒面试:面试时如何有效发挥口才

    2024-05-13 01:22:03       36 阅读