五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2335. Minimum Amount of Time to Fill Cups

2023-05-02 14:33 作者:您是打尖兒還是住店呢  | 我要投稿

You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up?2?cups with?different?types of water, or?1?cup of any type of water.

You are given a?0-indexed?integer array?amount?of length?3?where?amount[0],?amount[1], and?amount[2]?denote the number of cold, warm, and hot water cups you need to fill respectively.?

Return?the?minimum?number of seconds needed to fill up all the cups.

?

Example 1:

Input: amount = [1,4,2]

Output: 4

Explanation:?

One way to fill up the cups is:?

Second 1: Fill up a cold cup and a warm cup.?

Second 2: Fill up a warm cup and a hot cup.

Second 3: Fill up a warm cup and a hot cup.?

Second 4: Fill up a warm cup.?

It can be proven that 4 is the minimum number of seconds needed.

Example 2:

Input: amount = [5,4,4]

Output: 7

Explanation:?

One way to fill up the cups is:?

Second 1: Fill up a cold cup, and a hot cup.?

Second 2: Fill up a cold cup, and a warm cup.?

Second 3: Fill up a cold cup, and a warm cup.?

Second 4: Fill up a warm cup, and a hot cup.?

Second 5: Fill up a cold cup, and a hot cup.?

Second 6: Fill up a cold cup, and a warm cup.?

Second 7: Fill up a hot cup.

Example 3:

Input: amount = [5,0,0]

Output: 5

Explanation:?

Every second, we fill up a cold cup.

可以同時(shí)接2個(gè)不同類型的咖啡,也可以只接一種咖啡;

那么我們?nèi)绾伪WC接的次數(shù)最少,就要同時(shí)接2種咖啡的次數(shù)最多即可;

所以每次都要去看剩下的是哪2種咖啡剩的最多,所以每接一次就要排一次序,

于是就想到了優(yōu)先隊(duì)列,只是排序的規(guī)則是從大到小,而不是從小到大,

所以需要重寫一下compare的方法就行了;

下面是代碼:

Runtime:?3 ms, faster than?35.27%?of?Java?online submissions for?Minimum Amount of Time to Fill Cups.

Memory Usage:?40.4 MB, less than?35.50%?of?Java?online submissions for?Minimum Amount of Time to Fill Cups.


LeetCode 2335. Minimum Amount of Time to Fill Cups的評論 (共 條)

分享到微博請遵守國家法律
牙克石市| 红河县| 莲花县| 正安县| 康保县| 忻州市| 米易县| 浠水县| 广德县| 江油市| 天门市| 濮阳市| 安吉县| 大宁县| 曲麻莱县| 钟山县| 怀远县| 兴隆县| 舟曲县| 道孚县| 龙泉市| 自治县| 浮梁县| 铁力市| 宽甸| 栖霞市| 长白| 南通市| 德钦县| 临泉县| 通海县| 勃利县| 周至县| 抚松县| 安岳县| 沧源| 石狮市| 南昌市| 吉安市| 石棉县| 吐鲁番市|