파비의 매일매일 공부기록

2023.09.24 Today's Challenge 본문

Problem Solving/LeetCode

2023.09.24 Today's Challenge

fabichoi 2023. 9. 24. 23:45

https://leetcode.com/problems/champagne-tower/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

시뮬레이션 문제

class Solution:
    def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float:
        a = [[0] * k for k in range(1, 102)]
        a[0][0] = poured

        for r in range(query_row + 1):
            for c in range(r + 1):
                q = (a[r][c] - 1.0) / 2.0
                if q > 0:
                    a[r+1][c] += q
                    a[r+1][c+1] += q
        
        return min(1, a[query_row][query_glass])
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.09.26 Today's Challenge  (0) 2023.09.26
2023.09.25 Today's Challenge  (0) 2023.09.25
2023.09.23 Today's Challenge  (0) 2023.09.23
2023.09.22 Today's Challenge  (0) 2023.09.22
2023.09.21 Today's Challenge  (0) 2023.09.21
Comments