Re: [閒聊] 每日leetcode

作者: dont   2024-09-05 13:57:15
2028. Find Missing Observations
## 思路
先計算n個rolls的總和
如果不在全丟1或丟6的範圍內 就回傳[]
除上n, 讓所有骰子全丟a
剩下的餘數分配到b個骰子
## Code
```python
class Solution:
def missingRolls(self, rolls: List[int], mean: int, n: int) -> List[int]:
m = len(rolls)
total = (m+n) * mean - sum(rolls)
if total < n * 1 or total > n * 6:
return []
a, b = divmod(total, n)
return [a+1] * b + [a] * (n-b)
```
作者: Furina (芙寧娜)   2024-09-05 13:58:00
大師
作者: sustainer123 (caster)   2024-09-05 14:07:00
大師

Links booklink

Contact Us: admin [ a t ] ucptt.com