Leetcode 3100. Water Bottles II

1. 解题思路

这一题就是按照题目翻译一下,按照题中给出的规则不断进行bottle的兑换,直至无法兑换为止,即可得到最终的答案。

2. 代码实现

给出python代码实现如下:

class Solution:
    def maxBottlesDrunk(self, numBottles: int, numExchange: int) -> int:
        ans = 0
        while numBottles >= numExchange:
            ans += numExchange
            numBottles -= numExchange
            numExchange += 1
            numBottles += 1
        return ans + numBottles

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

相关推荐

  1. Leetcode 3100. Water Bottles II

    2024-04-01 00:50:01       36 阅读
  2. LeeCode 3130 DP / 组合数学

    2024-04-01 00:50:01       34 阅读
  3. LeetCode 300 最长递增子序列

    2024-04-01 00:50:01       61 阅读
  4. Leetcode 300 最长递增子序列

    2024-04-01 00:50:01       55 阅读
  5. LeetCode-300.最长递增子序列】

    2024-04-01 00:50:01       39 阅读
  6. LeetCode 300. 最长递增子序列

    2024-04-01 00:50:01       39 阅读
  7. leetcode300:最长递增子序列

    2024-04-01 00:50:01       27 阅读

最近更新

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

    2024-04-01 00:50:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-01 00:50:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-01 00:50:01       87 阅读
  4. Python语言-面向对象

    2024-04-01 00:50:01       96 阅读

热门阅读

  1. 什么是数据仓库

    2024-04-01 00:50:01       41 阅读
  2. 随机规划:求解报童问题期望值模型的算法方案

    2024-04-01 00:50:01       34 阅读
  3. 云资源调度和管理系统

    2024-04-01 00:50:01       32 阅读
  4. 日本出国留学一年费用大概多少钱

    2024-04-01 00:50:01       38 阅读
  5. ###用sh ``` 用sh ``json失败

    2024-04-01 00:50:01       47 阅读
  6. git-常用命令

    2024-04-01 00:50:01       44 阅读
  7. 【技术】Vue3 组件通讯方法有哪些

    2024-04-01 00:50:01       35 阅读
  8. python之函数的参数

    2024-04-01 00:50:01       43 阅读
  9. Git 实战教程

    2024-04-01 00:50:01       45 阅读
  10. FFmpeg入门指南

    2024-04-01 00:50:01       37 阅读