Day63 换酒问题

1518. 换酒问题

本来想用递归,结果好久也没搞定,还是看提示做出来的。

class Solution:
    def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
        result, remain = 0, 0
        result += numBottles
        remain = numBottles #剩下的空瓶
        #print(f'result: {result } remain:{remain}')
        while remain >= numExchange:
            result += remain//numExchange
            remain = remain//numExchange + remain%numExchange
            #print(f'result: {result } remain:{remain}')
        return result

你可能感兴趣的:(Day63 换酒问题)