# 2335. Minimum Amount of Time to Fill Cups ###### tags: `Leetcode` `Medium` `Priority Queue` `Greedy` Link: https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups/ ## 思路 $O(N)$ $O(1)$ 因为array size永远是3 所以即使sort 也没关系 每次看两个最大的amount中有没有0 没有的话就一次都接满 ## Code ```java= class Solution { public int fillCups(int[] amount) { Arrays.sort(amount); int ans = 0; while(amount[2]!=0){ ans++; amount[2]--; if(amount[1]>0) amount[1]--; Arrays.sort(amount); } return ans; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up