LeetCode 2028. 找出缺失的观测数据

LeetCode 2028. 找出缺失的观测数据,第1张

题目描述

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;
    }
};

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/562295.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-01
下一篇 2022-04-01

发表评论

登录后才能评论

评论列表(0条)

保存