1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class Solution { public int fillCups(int[] amount) { Arrays.sort(amount); if (amount[1] == 0) { return amount[2]; } amount[1]--; amount[2]--; return 1 + fillCups(amount); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { public int fillCups(int[] amount) { Arrays.sort(amount);
if (amount[0] + amount[1] <= amount[2]) { return amount[2]; } else { int t = amount[0] + amount[1] - amount[2]; if ((t & 1) == 0) { return t / 2 + amount[2]; } else { return (t - 1) / 2 + amount[2] + 1; } } } }
|
References
2335. Minimum Amount of Time to Fill Cups