Skip to content

Commit a02cac8

Browse files
committed
add 2244
1 parent fc91126 commit a02cac8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ LeetCode Solution In Hard Way
329329
|2258|[Number of Flowers in Full Bloom](https://leetcode.cn/problems/escape-the-spreading-fire/) | [C++](./src/Problem_2258_maximumMinutes.cc)|Hard|
330330
|2251|[Number of Flowers in Full Bloom](https://leetcode.cn/problems/number-of-flowers-in-full-bloom/) | [C++](./src/Problem_2251_fullBloomFlowers.cc)|Hard|
331331
|2246|[Longest Path With Different Adjacent Characters](https://leetcode.cn/problems/longest-path-with-different-adjacent-characters/) | [C++](./src/Problem_2246_longestPath.cc)|Hard|
332+
|2244|[Minimum Rounds to Complete All Tasks](https://leetcode.cn/problems/minimum-rounds-to-complete-all-tasks/) | [C++](./src/Problem_2244_minimumRounds.cc)|Medium|
332333
|2240|[Number of Ways to Buy Pens and Pencils](https://leetcode.cn/problems/number-of-ways-to-buy-pens-and-pencils/description/?envType=daily-question&envId=2023-09-01) | [C++](./src/Problem_2240_waysToBuyPensPencils.cc)|Medium|
333334
|2218|[Maximum Value of K Coins From Piles](https://leetcode.cn/problems/maximum-value-of-k-coins-from-piles/) | [C++](./src/Problem_2218_maxValueOfCoins.cc)|Hard|
334335
|2209|[Minimum Obstacle Removal to Reach Corner](https://leetcode.cn/problems/minimum-obstacle-removal-to-reach-corner/) | [C++](./src/Problem_2209_minimumObstacles.cc)|Hard|

Diff for: src/Problem_2244_minimumRounds.cc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <algorithm>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
class Solution
7+
{
8+
public:
9+
int minimumRounds(vector<int>& tasks)
10+
{
11+
std::sort(tasks.begin(), tasks.end());
12+
int ans = 0;
13+
int diff = 0;
14+
int n = tasks.size();
15+
for (int i = 0; i < n; i++)
16+
{
17+
if (i == 0 || tasks[i - 1] == tasks[i])
18+
{
19+
// 统计相同的数,当然用 unordered_map 缓存也可
20+
diff++;
21+
}
22+
else
23+
{
24+
if (diff < 2)
25+
{
26+
return -1;
27+
}
28+
ans += (diff + 3 - 1) / 3;
29+
diff = 1;
30+
}
31+
}
32+
// 计算最后一个相同的数
33+
if (diff < 2)
34+
{
35+
return -1;
36+
}
37+
ans += (diff + 3 - 1) / 3;
38+
return ans;
39+
}
40+
};

0 commit comments

Comments
 (0)