1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// @Title: 找出缺失的观测数据 (Find Missing Observations)
// @Author: 15816537946@163.com
// @Date: 2022-03-27 15:11:11
// @Runtime: 132 ms
// @Memory: 8.6 MB
func missingRolls(rolls []int, mean, n int) []int {
    missingSum := mean * (n + len(rolls))
    for _, roll := range rolls {
        missingSum -= roll
    }
    if missingSum < n || missingSum > n*6 {
        return nil
    }

    quotient, remainder := missingSum/n, missingSum%n
    ans := make([]int, n)
    for i := range ans {
        ans[i] = quotient
        if i < remainder {
            ans[i]++
        }
    }
    return ans
}