Leetcode 867 Solution

This article provides solution to leetcode question 867 (new-21-game)

https://leetcode.com/problems/new-21-game

Solution

class Solution:
    def new21Game(self, N: int, K: int, W: int) -> float:
        s = list(range(1, N - K + 2))
        a = 1
        for i in range(N - K + 1, N + 1):
            a = (1 / W) * (s[i - 1] - (s[i - 1 - W] if i - 1 - W >= 0 else 0))
            s.append(s[-1] + a)
        return a