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

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

LeetCode 2244. Minimum Rounds to Complete All Tasks

2023-04-21 16:23 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?integer array?tasks,?

where?tasks[i]?represents the difficulty level of a task.?

In each round, you can complete either 2 or 3 tasks of the?same difficulty level.

Return?the?minimum?rounds required to complete all the tasks,?

or?-1?if it is not possible to complete all the tasks.

?

Example 1:

Input: tasks = [2,2,3,3,2,4,4,4,4,4]

Output: 4

Explanation:?

To complete all the tasks, a possible plan is:

- In the first round, you complete 3 tasks of difficulty level 2.

- In the second round, you complete 2 tasks of difficulty level 3.?

- In the third round, you complete 3 tasks of difficulty level 4.?

- In the fourth round, you complete 2 tasks of difficulty level 4. ??

It can be shown that all the tasks cannot be completed in fewer than 4 rounds,?

so the answer is 4.

Example 2:

Input: tasks = [2,3,3]

Output: -1

Explanation:?

There is only 1 task of difficulty level 2,?

but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.

?

Constraints:

  • 1 <= tasks.length <= 105

  • 1 <= tasks[i] <= 109

所有的任務(wù)都要完成,那么我們就去計算每個任務(wù)出現(xiàn)的次數(shù),如果出現(xiàn)的次數(shù)<2,那么就不能完成,這時候就返回-1;

如果都符合要求,那么就去判斷如何用最少的round去完成,那么我們優(yōu)先用3去判斷余數(shù),余數(shù)為0,直接全部3, 余數(shù)為1,那么相當(dāng)于最后4個任務(wù)要用2次round去完成,

同理余數(shù)是2的時候,最后2個任務(wù)用1次round完成;

下面就是代碼了,主要就是用hashmap即可;

Runtime:?40 ms, faster than?36.31%?of?Java?online submissions for?Minimum Rounds to Complete All Tasks.

Memory Usage:?56.8 MB, less than?61.18%?of?Java?online submissions for?Minimum Rounds to Complete All Tasks.


LeetCode 2244. Minimum Rounds to Complete All Tasks的評論 (共 條)

分享到微博請遵守國家法律
任丘市| 阜新市| 永吉县| 大安市| 米易县| 开平市| 泗水县| 大田县| 英山县| 英德市| 南平市| 开阳县| 巨野县| 五华县| 青海省| 赞皇县| 开江县| 东山县| 新津县| 新干县| 浮梁县| 平和县| 天台县| 枞阳县| 金寨县| 大石桥市| 邯郸市| 龙州县| 曲周县| 锡林浩特市| 邓州市| 临夏县| 泰顺县| 阜城县| 沙洋县| 乌鲁木齐县| 栖霞市| 高碑店市| 化德县| 洪湖市| 南部县|