2028. 找出缺失的观测数据
解法:class Solution {
public:
vector<int> missingRolls(vector<int>& rolls, int mean, int n) {
vector<int> ans;
int m = rolls.size();
int t = mean * (m + n);
for (auto i : rolls) t -= i;
if (t < n || t > 6 * n) return ans;
for (int i = 0; i < n; i++) ans.emplace_back(t / n);
if (t / n * n < t)
{
int d = t - (t / n * n);
for (int i = 0; d > 0; i++, d--) ans[i]++;
}
return ans;
}
};
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)