1518. 换水问题
为保证权益,题目请参考 1518. 换水问题(From LeetCode).
解决方案1
Python
python
# 1518. 换酒问题
# https://leetcode-cn.com/problems/water-bottles/
class Solution:
def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
ans = numBottles
while numBottles >= numExchange:
last = numBottles % numExchange
newOne = numBottles // numExchange
ans += newOne
numBottles = last + newOne
return ans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14