LeetCode – 799. Champagne Tower

題目連結: https://leetcode.com/problems/champagne-tower/

參考解法: https://www.youtube.com/watch?v=OqXzKsEWM44

    func champagneTower(_ poured: Int, _ query_row: Int, _ query_glass: Int) -> Double {
		var tower: [[Double]] = []
		tower.append([Double(poured)])
		for i in 0 ..< query_row {
			tower.append(Array(repeating: 0, count: i + 2))
			for j in 0 ... i {
				if tower[i][j] > 1 {
					tower[i+1][j] += (tower[i][j] - 1) / 2
				    tower[i+1][j+1] += (tower[i][j] - 1) / 2
				}
			}
		}
		return tower[query_row][query_glass] > 1 ? 1 : tower[query_row][query_glass]
    }