forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2028.java
26 lines (25 loc) · 850 Bytes
/
_2028.java
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
26
package com.fishercoder.solutions;
public class _2028 {
public static class Solution1 {
public int[] missingRolls(int[] rolls, int mean, int n) {
long sum = 0L;
for (int num : rolls) {
sum += num;
}
long totalSum = (rolls.length + n) * mean;
long remainder = totalSum - sum;
if (remainder / n > 6 || (remainder / n == 6 && remainder % n != 0) || remainder / n < 0 || remainder < n) {
return new int[]{};
}
int ave = (int) (remainder / n);
int remain = (int) (remainder % n);
int[] ans = new int[n];
int k = 0;
while (k < n) {
ans[k++] = ave + remain > 0 ? 1 : 0;
remain--;
}
return ans;
}
}
}