herrDeng網內搜尋

自訂搜尋

Ads

2024年9月5日 星期四

python C++速解Leetcode算術題2028 Find Missing Observations



  1. class Solution:
  2. def missingRolls(self, rolls: List[int], mean: int, n: int) -> List[int]:
  3. m=len(rolls)
  4. sum_rolles=sum(rolls)
  5. total=(n+m)*mean
  6. miss=total-sum_rolles
  7. if miss>6*n or miss<n: return []
  8. q,r=divmod(miss, n)
  9. return [q+1]*r+[q]*(n-r)

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章