MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / new21Game

Method new21Game

java/0837-new-21-game.java:2–23  ·  view source on GitHub ↗
(int n, int k, int maxPts)

Source from the content-addressed store, hash-verified

1class Solution {
2 public double new21Game(int n, int k, int maxPts) {
3 if (k == 0) {
4 return 1.0;
5 }
6
7 double windowSum = 0.0;
8 for (int i = k; i < k + maxPts; i++) {
9 windowSum += (i <= n) ? 1.0 : 0.0;
10 }
11
12 Map<Integer, Double> dp = new HashMap<>();
13 for (int i = k - 1; i >= 0; i--) {
14 dp.put(i, windowSum / maxPts);
15 double remove = 0.0;
16 if (i + maxPts <= n) {
17 remove = dp.getOrDefault(i + maxPts, 1.0);
18 }
19 windowSum += (dp.get(i) - remove);
20 }
21
22 return dp.get(0);
23 }
24}

Callers

nothing calls this directly

Calls 2

putMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected