Skip to content

Commit 57a8c24

Browse files
committed
Add champagne tower
1 parent 8bbc0f4 commit 57a8c24

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: 799-champagne-tower/solution.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:
3+
grid = [[0 for i in range(query_glass+1)] for j in range(query_row+1)]
4+
grid[0][0] = poured
5+
6+
for i in range(1, query_row+1):
7+
for j in range(query_glass+1):
8+
left = 0
9+
if i-1 >= 0 and j-1 >= 0 and grid[i-1][j-1] > 1:
10+
left = (grid[i-1][j-1]-1) / 2
11+
top = 0
12+
if i-1 >= 0 and grid[i-1][j] > 1:
13+
top = (grid[i-1][j]-1) / 2
14+
15+
grid[i][j] = left+top
16+
17+
return grid[query_row][query_glass] if grid[query_row][query_glass] < 1 else 1

0 commit comments

Comments
 (0)