Champagne Tower LeetCode solution in Python
1# Runtime: 392 ms (Top 9.30%) | Memory: 14.4 MB (Top 11.38%)2class Solution:3def champagneTower(self, poured: int, r: int, c: int) -> float:4quantity = defaultdict(int)5quantity[(0, 0)] = poured6for i in range(r + 1):7flag = False8for j in range(i + 1):9prev_flow = quantity[(i, j)] - 110if prev_flow <= 0:11continue12flag = True13quantity[(i, j)] = 114quantity[(i + 1, j)] += prev_flow / 215quantity[(i + 1, j + 1)] += prev_flow / 216if not flag:17break18return quantity[(r, c)]